Local Event is firing for Everyone

I have a local script in StarterPlayerScripts that handles every event that should fire for the Client only. It is for one of those difficult obby games that plays tricks on the player. The issue, though, is each event in this local script is firing for every player on the server.

In this example, the player touches an invisible trigger which tweens the visibility of a part the player is supposed to land on, making them fall through it and die.

Example event:

local function event1(p)

	local dbtime = 3

	local trigger = triggers.trigger
	local affectedpart = affected.disappearpart

	local tInfo = TweenInfo.new(
		.15, -- Time/Speed
		Enum.EasingStyle.Linear, 
		Enum.EasingDirection.InOut,
		0, 
		false,
		0
		)

	local FadeIn = ts:Create(affectedpart, tInfo, {Transparency = 0, CanCollide = true})
	local FadeOut = ts:Create(affectedpart, tInfo, {Transparency = 1, CanCollide = false})
	
	if alive then
	trigger.CanTouch = false
	FadeOut:Play()
	affectedpart.Sound:Play()
	wait(1)
	FadeIn:Play()
	affectedpart.Sound2:Play()
	wait(3)
	trigger.CanTouch = true
	wait()	
	else return
	end
end
triggers.trigger.Touched:Connect(function(hit)
	event1(p)
end)

can you please provide the full code

Sure, here it is

local p = game.Players.LocalPlayer
local c = p.Character or p.CharacterAdded:Wait()

local ts = game:GetService("TweenService")
local triggers = game.Workspace.triggers
local affected = game.Workspace.affected
local rs = game:GetService("ReplicatedStorage")

local alive = c:WaitForChild("Humanoid").Health >=1

 
--// functions //--

local function event1(p)

	local dbtime = 3

	local trigger = triggers.trigger
	local affectedpart = affected.disappearpart

	local tInfo = TweenInfo.new(
		.15, -- Time/Speed
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.InOut, 
		0,
		false,
		0
		)

	local FadeIn = ts:Create(affectedpart, tInfo, {Transparency = 0, CanCollide = true})
	local FadeOut = ts:Create(affectedpart, tInfo, {Transparency = 1, CanCollide = false})
	
	if alive then
	trigger.CanTouch = false
	FadeOut:Play()
	affectedpart.Sound:Play()
	wait(1)
	FadeIn:Play()
	affectedpart.Sound2:Play()
	wait(3)
	trigger.CanTouch = true
	wait()	
	else return
	end
end



--// triggers //--

triggers.trigger.Touched:Connect(function(hit)
	event1(p)
end)

A touched event only cares a part touched it. This means if any player touches it, then all players will see that. You need to check that the part that touched it (p) is a child of the player.Character.

So if p.Parent == game.Players.LocalPlayer.Character then call function end

1 Like

Thx, this works perfectly. Appreciate it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.