Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
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.

Ad

Answer this question