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

What is wrong with my code? It doesn't work. Cdfdfsdfdfsdfdf

Asked by 6 years ago

Here is my localscript code; inside the startergui:



local RemoteEvent = game.Workspace:WaitForChild("Music"):WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer canplay = true RemoteEvent.OnClientEvent:Connect(function() if canplay then local sound = player.PlayerGui:WaitForChild("sound") sound:Play() sound.Looped = true print(otherpart) canplay = false end end)

Here is my script code inside the workspace:

local part = game.Workspace.Music
local RemoteEvent = Instance.new("RemoteEvent", part)
local sound = game.Workspace["Final Boss"]
canplay = true 

local function muziekspelen(otherpart)
    print(otherpart)
    local humanoid = otherpart.Parent:FindFirstChild("Humanoid")

    if humanoid and canplay then
        local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
        canplay = false
        RemoteEvent:FireClient(player)
sound.Parent = player.PlayerGui
sound:Play()
sound.Looped = true

    end
    canplay = true
end

part.Touched:connect(muziekspelen)

I don't want to repeat the sound everytime it's being touched by the localplayer. Does anyone know how to do this?

0
Please clarify your question. What is your code supposed to do? ...Cdfdfsdfdfsdfdf?? awesomeipod 607 — 6y
0
If a certain block called music get's touced it needs to play a sound that can only be heared by the localplayer i got that working but if u keep walking on the block the sound will just replay kattenverzorger 23 — 6y

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

You should call Player:WaitForChild("PlayerGui"), just because there's no guarantee it's loaded.

Nonetheless, there's no reason to do this server-side at all. You should listen for the BasePart.Touched event client-side to begin with, instead of wasting bandwith and adding latency.

You can also get rid of the Instance:WaitForChild() calls for both the music and the RemoteEvent. Remotes should be stored in a special folder named Network or Remote or Remotes or something of the sort in game.ReplicatedStorage.

Ad

Answer this question