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

How do I make 2 players touch a part at the same time & the part only clone once for each?

Hi, so I tried to make a part that when you touch it it clones a script into the player's playergui. When two people touch the part,** I want the script to clone the localscript once into each player's playergui and never again.** How do I set up the script so that if one player steps on the part while another is standing on it (and already has the LocalScript) it will only clone into the most recent player's playergui without the need for a debounce pause?

local Players = game:GetService("Players")
local cutscene=script.AnnouncementScript
local cutsceneinsert=cutscene:Clone()
local part = script.Parent
local function onTouched(part)
	
		local player = Players:GetPlayerFromCharacter(part.Parent)
		if not player then return end
		cutsceneinsert.Parent=player.PlayerGui
		part.Parent:FindFirstChild("Humanoid").JumpPower = 0
		part.Parent:FindFirstChild("Humanoid").WalkSpeed = 0

		wait(13)
		
		part.Parent:FindFirstChild("Humanoid").JumpPower = 50
		part.Parent:FindFirstChild("Humanoid").WalkSpeed = 20
	
	
	
		
	end



end
part.Touched:Connect(onTouched)

1 answer

local Players = game:GetService("Players")
local cutscene=script.AnnouncementScript
local cutsceneinsert=cutscene:Clone()
local part = script.Parent
local function onTouched(part)

        local player = Players:GetPlayerFromCharacter(part.Parent)
        if not player or player.PlayerGui:FindFirstChild(cutsceneinsert.Name) then return end
        cutsceneinsert.Parent=player.PlayerGui
        part.Parent:FindFirstChild("Humanoid").JumpPower = 0
        part.Parent:FindFirstChild("Humanoid").WalkSpeed = 0

        wait(13)

        part.Parent:FindFirstChild("Humanoid").JumpPower = 50
        part.Parent:FindFirstChild("Humanoid").WalkSpeed = 20




    end



end
part.Touched:Connect(onTouched)

My edit here is: 'if not player or player.PlayerGui:FindFirstChild(cutsceneinsert.Name) then return end'

I check if the user's PlayerGui contains the cutscene GUI and if so, it will return out of the function.

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