Hello! I am having trouble with a system I created and I am wondering if anybody could help.
It is a timed section of the game where you are supposed to beat it in a certain amount of time, however if two (or more) people start the timer and one person fails, the timer will end for everyone. This also happens if someone hasn’t started the timer and they fail. You can obviously see how this causes an issue.
Here is a video showing the problem:
Here is the code used:
local buttons = game.Workspace.Map.RushZones.Buttons:GetChildren()
local doors = game.Workspace.Map.RushZones.Doors:GetChildren()
local stopTimer = game.Workspace.Map.RushZones.Failed:GetChildren()
local plr = game.Players.LocalPlayer
local timer = 60
local isRunning = false
-- main countdown function
local function countdown()
plr.PlayerGui.RushzoneTimer.timer.Visible = true
isRunning = true
for i = timer, 1, -1 do
if isRunning == true then
plr.PlayerGui.RushzoneTimer.timer.Text = i
task.wait(1)
else
break
end
end
isRunning = false
plr.PlayerGui.RushzoneTimer.timer.Visible = false
end
-- if you touch invisible block the timer ends
for i, v in pairs(stopTimer) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if isRunning == true then
isRunning = false
else
return
end
end
end)
end
-- button to start the timer
for i, button in pairs(buttons) do
button.ProximityPrompt.Triggered:Connect(function(plr)
button.ProximityPrompt.Enabled = false
for i, door in pairs(doors) do
door.Transparency = 1
door.CanCollide = false
countdown()
door.Transparency = 0
door.CanCollide = true
end
button.ProximityPrompt.Enabled = true
end)
end
Both proximityPromot and touched will fire if other players/objects trigger it. For both you need to check that the player triggering the event == the local player.
E.g
button.ProximityPrompt.Triggered:Connect(function(plr)
if plr == game.Players.LocalPlayer then
-- continue here
I’m not sure if I’m doing this correctly but I’m getting an error:
Here is the updated code:
for i, v in pairs(stopTimer) do
v.Touched:Connect(function(plr, hit)
if hit.Parent:FindFirstChild("Humanoid") then -- this is line 34
if plr == game.Players.LocalPlayer then
if isRunning == true then
isRunning = false
else
return
end
end
end
end)
end
for i, button in pairs(buttons) do
button.ProximityPrompt.Triggered:Connect(function(plr)
if plr == game.Players.LocalPlayer then
button.ProximityPrompt.Enabled = false
for i, door in pairs(doors) do
door.Transparency = 1
door.CanCollide = false
countdown()
door.Transparency = 0
door.CanCollide = true
end
button.ProximityPrompt.Enabled = true
end
end)
end
As explained by BasePart | Roblox Creator Documentation you can only have 1 argument inside a Touched:Connect, in this case, this argument is plr. The other argument hit has a value of nil