Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with this script?

Asked by 9 years ago

I'm trying to make it so when a player joins the game, it clones a IntValue from the Lighting to the Player. This is the script I'm using below but it only works once on one player and fails to work on the next, what is wrong with it? Thanks.

function onPlayerEntered(newPlayer)
local iv = game.Lighting.playerstats
iv.Parent = newPlayer
iv.Clone()
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

Log in to vote
1
Answered by 9 years ago

Your problem is that you aren't cloning the int value when you are putting it into the player

function onPlayerEntered(newPlayer)
    local iv = game.Lighting.playerstats:Clone() --You also have to use ":" when cloning
    iv.Parent = newPlayer
end

game.Players.PlayerAdded:connect(onPlayerEntered)

This would clone the value and set the variable 'iv' as the cloned int val and then parent it to 'newPlayer'

0
Spelt 'connect' at the bottom wrong, but when corrected it worked. Cheers. Ryan5124KBCP 15 — 9y
0
Wups, sorry! VariadicFunction 335 — 9y
Ad

Answer this question