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

Why is it affecting everyone?

So I've got a part in my game, that when touched will trigger a script, that triggers a remote event, which in turn triggers a second localscript that disables the players controls.

'Touched Part?' script:

local disableControlsRE = game:GetService("ReplicatedStorage"):FindFirstChild("DisableControls")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		
		disableControlsRE:FireAllClients()
		
	end
end)

^^^ This script triggers a RemoteEvent which triggers the following localscript:

local disableControlsRE = game:GetService("ReplicatedStorage"):FindFirstChild("DisableControls")

disableControlsRE.OnClientEvent:Connect(function(hit)

	local PlayerModule = require(game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
	
	local controls = PlayerModule:GetControls()
	
end)

It works perfectly well, and does it's job, however it appears to be happening to everyone and not just the triggering Player, does anyone have any tips, solutions or help please?

1 answer

✓ Accepted answer

Of course it will trigger to every player in the game. Your code says it itself.

local disableControlsRE = game:GetService("ReplicatedStorage"):FindFirstChild("DisableControls")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
	local player = game.Players:GetPlayersFromCharacter(hit.Parent)

        -- disableControlsRE:FireAllClients() -- FireAllClients fires the remote event to (every single player in the game.)

	disableControlsRE:FireClient(player) -- This is what you need. You pass the player that touched the brick.

    end
end)

There you go. Hope it helps

2 comments

0

thank you, sorry I didn't see that, I'm fairly new so I didn't realise "FireAllClients()" fired everyone :thumbsup:

0

You're Welcome. Glad I could help :)

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