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

Music playing Localscript added with onPlayerAdded not working?

Asked by
Roytt 64
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So have this placed under the workspace in a normal script

 function onPlayerAdded(player)
    player.CharacterAdded:connect(function(character)
    script.Dinamic:clone().Parent = character
end)
end
game.Players.PlayerAdded:connect(onPlayerAdded)

Dinamic is a localscript that has the following inside:

local character = script.Parent
local player = game.Players.LocalPlayer

if script.Value.Value == 1 then
    player.PlayerGui.Flute:Play()
elseif script.Value.Value == 2 then
    player.PlayerGui.Piano:Play()
end

local playing = false --false = flute true = piano



script.Parent.Head.Touched:connect(function(hit)
    if hit.Name == "Music" and playing == false then
        player.PlayerGui.Flute:Stop ()
        player.PlayerGui.Piano:Play ()
        playing = true
        wait()
    elseif hit.Name == "Music" and playing == true then
        player.PlayerGui.Piano:Stop ()
        player.PlayerGui.Flute:Play ()
        playing = false
        wait()
    end
end)

Value is a numValue placed inside the localscript and its default value is 1. This script works correctly in solo mode but in online mode it does not work and I have no idea why, maybe the PlayerAdded Event doesn't fire correctly ?

0
I already read it but I can't figure out what's wrong with it, I did a few changes to the script before posting here based on what I read from there. I'm pretty new to this so some things that may seems obvious are not to me. Roytt 64 — 8y

Answer this question