|
| 06 Aug 2013 12:12 PM |
So I have a script, with a localscript inside it. I want to copy it into the player model. This is my script:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:wait() newScript = script.LocalScript:clone() newScript.Parent = player.Character end)
What is the problem and how do I fix it?
All the best, filiptibell |
|
|
| Report Abuse |
|
|
Soquick
|
  |
| Joined: 01 Nov 2012 |
| Total Posts: 1497 |
|
|
| 06 Aug 2013 12:16 PM |
wait() game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:wait() newScript = script.LocalScript:clone() newScript.Parent = player.Character newScript.Disabled = false end) |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2013 12:41 PM |
Tried in play server and start player as I thought that was the problem, but when I did I only got a "waiting for character" loop (Also in normal "Play" mode after saving). The server output said that it was waiting for the players backpack.
I managed to fix the looping problem by adding an if statement:
wait() game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:wait() if game.Players.Character.IntroScript == nil then newScript = script.IntroScript:clone() --Changed "LocalScript" name to IntroScript newScript.Parent = player.Character newScript.Disabled = false end end)
But it still does not copy the localscript.
Any thoughts? |
|
|
| Report Abuse |
|
|
Desperian
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 3371 |
|
|
| 06 Aug 2013 12:49 PM |
1) The 'Players' service doesn't have a 'Character' property. 2) To check if something is there, or not, you should use the ':FindFirstChild()' method.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:wait() if player.Character:FindFirstChild("IntroScript") == nil then newScript = script.IntroScript:clone() --Changed "LocalScript" name to IntroScript newScript.Parent = player.Character newScript.Disabled = false end end) |
|
|
| Report Abuse |
|
|
Soquick
|
  |
| Joined: 01 Nov 2012 |
| Total Posts: 1497 |
|
|
| 06 Aug 2013 12:54 PM |
oops, mine errored. I wasnt thinking, I did a :wait() instead of :connect(function(char) |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2013 12:55 PM |
I just noticed both of those errors when I checked the servers output (slight laziness from my part), and also fixed them... Basically I c/p;ed most of this from the wiki. (also laziness)
Used a debounce instead of checking if the script is there:
debounce = false wait() game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:wait() if debounce == false then newScript = script.IntroScript:clone() newScript.Parent = player.Character newScript.Disabled = false debounce = true end end)
But when those 2 problems are fixed I get the freezing bug. (similar to the "Waiting for character", but without the waiting for character part...lol)
And I have no idea why. Any thoughts? |
|
|
| Report Abuse |
|
|
Desperian
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 3371 |
|
|
| 06 Aug 2013 12:57 PM |
| You do realise that after one player that script will stop working? You never set the debounce variable back to false (Don't know why you even needed a debounce), so the if statement will never be satisfied after the first player. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2013 12:59 PM |
| Yes, I did realize that. But that isn't the problem right now, now I just want to make it so that I can test if it even works. And since the script still does not work... well, yeah. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2013 01:00 PM |
| The debounce was my lazy way of fixing the error with finding if the IntroScript was there or not. |
|
|
| Report Abuse |
|
|
| |
|
Voidion
|
  |
| Joined: 01 Aug 2011 |
| Total Posts: 2668 |
|
|
| 07 Aug 2013 04:10 AM |
You're just trying to clone a localscript into the player's character, correct? What is with the confusion in this thread...?
game.Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) script.LocalScript:Clone().Parent = Character end) end) |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2013 04:24 AM |
Yes, you're completely correct Voidion.... But it either doesn't work, or it crashes the whole place (character doesn't load). Tried several methods but none worked :s
Tried your code, same result (LocalScript not getting copied) |
|
|
| Report Abuse |
|
|
Voidion
|
  |
| Joined: 01 Aug 2011 |
| Total Posts: 2668 |
|
|
| 07 Aug 2013 04:27 AM |
That is odd... Are you testing this correctly? Tools > Test > Start Server and then Tools > Test > Start Player |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2013 04:28 AM |
| Yup, also tested it by saving the whole place and using an official roblox server (normal "Play" mode) |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2013 04:42 AM |
It is possible to copy the localscript though right? Or is there any interference due to the fact that the server copies it and the script is local?
Just a thought... |
|
|
| Report Abuse |
|
|
Voidion
|
  |
| Joined: 01 Aug 2011 |
| Total Posts: 2668 |
|
|
| 07 Aug 2013 04:45 AM |
"It is possible to copy the localscript though right? " Yes. The fact that you crash or your character is not loading has to be something with the studio itself. I don't see why this would at all be a problem, but apparently it is... |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2013 05:21 AM |
I completely got rid of the script and modified the LocalScript so that it works from PlayerGUI instead. But it doesn't really work (lol)
New thread about it:
http://www.roblox.com/Forum/ShowPost.aspx?PostID=108768465 |
|
|
| Report Abuse |
|
|