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

can someone tell me whats wrong with this short script?

Asked by
mehssi 20
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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?

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

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

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)
Ad

Answer this question