Touch event problem

I’m making a game in wich a player is selected to do a wipeout obby, and he has 3 minutes to make it. I’m trying to make a touch event that when the player gets to the end, the script restarts, but even when no is touching it, it restarts, breaking the game. Here’s the part of the code:

repeat
workspace.Time.Value = workspace.Time.Value - 1
wait(1)
until workspace.Time.Value==0 or workspace.map.Win.WinPart2.Touched
if workspace.Time.Value==0 then
workspace.map.Win.WinPart2:Destroy()
workspace.map.Win.Winpart3.Position = Vector3.new(1025.471, 94.3, -23161.836)

workspace.Time.Value = 240
workspace.Fail:Play()
local Hint = Instance.new("Message")
Hint.Parent = workspace
Hint.Text = "Time's up!"
wait(2.5)
Hint:Destroy()
wait(6.1)
tp2()
elseif workspace.map.Win.WinPart2.Touched and workspace.Time.Value>0 then
workspace.map.Win.WinPart2:Destroy()
workspace.map.Win.Winpart3.Position = Vector3.new(1025.471, 94.3, -23161.836)
workspace.Time.Value = 240
workspace.Victory:Play()
local Hint = Instance.new("Message")
Hint.Parent = workspace
Hint.Text = "The player made it!"
wait(2.5)
Hint:Destroy()
wait(6.1)
tp2()
end
end

I don’t even know where’s the problem in the script, it should only activate when a player touches it.

Hi so the Touched event is basically an event so you will need to connect it to a function for it to have a use

local Win2Touched = false
workspace.Win.WinPart2.Touched:Connect(function(h)
Win2Touched = true
end)

Implement something like this to create an actual bool value for you to check to see if it was touched

If you want more information on the Touched Event just go here

I don’t know where I can implement this at my script.

local Win2Touched = false
workspace.Win.WinPart2.Touched:Connect(function(h)
Win2Touched = true
end)

repeat
workspace.Time.Value = workspace.Time.Value - 1
wait(1)
until workspace.Time.Value==0 or Win2Touched == true
if workspace.Time.Value==0 and Win2Touched == false then
workspace.map.Win.WinPart2:Destroy()
workspace.map.Win.Winpart3.Position = Vector3.new(1025.471, 94.3, -23161.836)

workspace.Time.Value = 240
workspace.Fail:Play()
local Hint = Instance.new("Message")
Hint.Parent = workspace
Hint.Text = "Time's up!"
wait(2.5)
Hint:Destroy()
wait(6.1)
tp2()
elseif Win2Touched ==true and workspace.Time.Value>0 then
workspace.map.Win.WinPart2:Destroy()
workspace.map.Win.Winpart3.Position = Vector3.new(1025.471, 94.3, -23161.836)
workspace.Time.Value = 240
workspace.Victory:Play()
local Hint = Instance.new("Message")
Hint.Parent = workspace
Hint.Text = "The player made it!"
wait(2.5)
Hint:Destroy()
wait(6.1)
tp2()
end
end

something similar to this

1 Like

Thx a lot bud. I was trying to figure this out for hours.

1 Like