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

local script not working for this the OnClientEvent not working?

this is script

	local Goo = script.Parent
	local team = BrickColor.new("Dark stone grey")
	local infect = game.ReplicatedStorage.GetInfect
	local waitd = false
 
	Goo.Touched:Connect(function(hit)
	    if not waitd then
	        local plr = game.Players:GetPlayerFromCharacter(hit.Parent);
	        if plr then
	            plr.TeamColor = team
	    end
	        infect:FireClient(plr)
	        waitd = true
	    end
	end)

this is a local script

local infect = game.ReplicatedStorage.GetInfect
local sound = script.Sound

infect.OnClientEvent:Connect(function()
    sound.Playing = true
end)

7 comments

0

I think you've forgot about you debounce, "waitd". Your Server Script will run as soon as it get's Touched, which I'm pretty sure all Parts do when you start a game, and it will fire the Event to plr, which does not exist because it wasn't a player who touched the brick. And then the Script will never run again.

0

i will test for debounce

0

the team color change but sound not play

0

and plr mean player that hit brick

0

nothing in output

0

You should move both line 12 and 13 inside your if plr then block

0

spjureeedd it not working and same problem onclientevent not working

1 answer

Here is your fixed script.

Regular Script:

local infect = game.ReplicatedStorage:WaitForChild("GetInfect")

local debounce = false

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:getPlayerFromCharacter(hit.Parent)
    if player then
        if not debounce then
            debounce=true
            infect:fireClient(player)
            player.TeamColor = BrickColor.new("Dark stone grey")
        end
    end
end)

LocalScript:

local infect = game.ReplicatedStorage:WaitForChild("GetInfect")
local sound = script.Parent.Sound

infect.OnClientEvent:Connect(function()
sound:Play()
end)

Let me know if this works. If it doesn't reply to this answer and I will investigate further.

4 comments

0

it not working

0

like same problem the onclient not working

0

You forgot about the debounce as well...

0

And this is bad, you've got 795 reputation and still just give the asker the working script, you don't explain anything or tell them what was wrong

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