How to not make this fire on all clients?

workspace:WaitForChild("Part").Touched:Connect(function()
	if debounce == false then
		debounce = true
		local PlayerGui = players.LocalPlayer:WaitForChild("PlayerGui")
		gui:WaitForChild("CountDown").Visible = true
		gui:WaitForChild("Revive").Visible = true
		char:FindFirstChild("HumanoidRootPart").Anchored = true
		test()
		countDown()
		local rem = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
		hum.Health = 0
		task.wait(1)
		debounce = false
	end
end)

When the player touches the part the GUI appears on all players screens. Please help.:slight_smile:

1 Like

If it is a normal script then change it to a LocalScript.

Thanks for the response! It is already a local script.

Where is the LocalScript located?

image
Here’s the entire script:

local players = game:GetService("Players")
local gui = script.Parent

local plr = players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local function test()
	print("success")
	local tweenservice = game:GetService("TweenService")

	local UI = gui:WaitForChild("Revive")

	local info1 = TweenInfo.new(
		0.5, -- Time it takes to fade
		Enum.EasingStyle.Circular -- Type of transition
	)

	local startpoint = {}
	startpoint.BackgroundTransparency = (1)


	local endPoint1 = {}
	endPoint1.BackgroundTransparency = (0)


	local fade = tweenservice:Create(UI, info1, endPoint1)
	fade:Play()
end

local debounce = false

local CDText = script.Parent:WaitForChild("CountDown"):WaitForChild("TextLabel")

local function countDown()
	for i = 20, 0, -1 do
		CDText.Text = tostring(i)
		task.wait(1)
	end
end

workspace:WaitForChild("Part").Touched:Connect(function()
	if debounce == false then
		debounce = true
		local PlayerGui = players.LocalPlayer:WaitForChild("PlayerGui")
		gui:WaitForChild("CountDown").Visible = true
		gui:WaitForChild("Revive").Visible = true
		char:FindFirstChild("HumanoidRootPart").Anchored = true
		test()
		countDown()
		local rem = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
		hum.Health = 0
		task.wait(1)
		debounce = false
	end
end)

Try this:

workspace:WaitForChild("Part").Touched:Connect(function(otherPart)
	if debounce == false and otherPart:IsDescendantOf(char) then
		debounce = true
		local PlayerGui = players.LocalPlayer:WaitForChild("PlayerGui")
		gui:WaitForChild("CountDown").Visible = true
		gui:WaitForChild("Revive").Visible = true
		char:FindFirstChild("HumanoidRootPart").Anchored = true
		test()
		countDown()
		local rem = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
		hum.Health = 0
		task.wait(1)
		debounce = false
	end
end)

This basically checks if the otherPart is a descendant of the character of the player who touched it, and if it is, only affect that player.

1 Like
local tweens = game:GetService("TweenService")

local frame = script.Parent
local countDownFrame = frame:WaitForChild("CountDown")
local coutnDownLabel = countDownFrame:WaitForChild("TextLabel")

local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local countDown = playerGui:WaitForChild("CountDown")
local revive = playerGui:WaitForChild("Revive")
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")

local tweenShow = tweens:Create(revive, TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.Out), {BackgroundTransparency = 1})
local tweenHide = tweens:Create(revive, TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.In), {BackgroundTransparency = 0})

local part = workspace.Part
local debounce = false

local function tweenGuiFrame()
	tweenShow:Play()
	tweenShow.Completed:Wait()
	tweenHide:Play()
	tweenHide.Completed:Wait()
end

local function doCountDown()
	for i = 20, 0, -1 do
		coutnDownLabel.Text = tostring(i)
		task.wait(1)
	end
end

part.Touched:Connect(function(otherPart)
	if debounce then
		return
	end
	
	if otherPart:IsDescendantOf(character) then
		debounce = true
		countDown.Visible = true
		revive.Visible = true
		hrp.Anchored = true
		humanoid.Health = 0
		tweenGuiFrame()
		doCountDown()
		task.wait(1)
		debounce = false
	end
end)

I know this is solved but I just wanted to do some general cleaning up.

2 Likes