Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

can someone tell me whats wrong with this short script?

local plyr = game.Players:FindFirstChild(game.Workspace.Goals.SoccerBall.Kicker.Value)
game.Workspace.Goals.SoccerBall.Kicker.Changed:connect(function()
script.Parent.Parent.goalmusic.SoundId = "rbxassetid://" .. plyr.hiddenstats.Value.Value	
end)

if a player touches the soccer ball his name goes on the Kicker.Value (this works) I use the Kicker.Value to find the player using game.Players:FindFirstChild(game.Workspace.Goals.SoccerBall.Kicker.Value) then I initiate the function after the Kicker.Value is changed then I make the script.Parent.Parent.GoalMusic.SoundID equal to the hidden stats.Value.Value of the player who just kicked the soccer ball

did I do anything wrong?

1 comment

0

Put the code inside a code block (The Lua button). If you don't do this soon you will get your question moderated.

1 answer

You're defining plr before the actual Changed event. It looks like you want to get the player from the value every time the value changes, but instead you're getting whatever the value starts as.

local kicker=workspace.Goals.SoccerBall.Kicker
kicker.Changed:connect(function()
	script.Parent.Parent.goalmusic.SoundId="rbxassetid://"..game.Players:FindFirstChild(kicker.Value).hiddenstats.Value.Value
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.