Only using this:
Results to this:
In other word, no UI has appeared, with no errors.
Try printing p and hit and hit.Parent
print(p, hit, hit.Parent)
Make sure you put that after the p variable
Ah nevermind the prints I realized I forgot to add the line that makes it visible her you go:
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
wait(1)
end
hit.Parent.Humanoid.Health -= 500
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
end
end
end)
before i test that out, shouldnt i change these around? otherwise we end the script before killing
No that end is for the countdown loop if you put the killing inside the loop then it will kill after the first second aka every time the loop runs.
That should work. I’m sorry but I have to go now!
Now it works perfectly besides this one issue:
I do appreciate the amount of help you’ve given, its really helped out. And anyone else that helped too <3
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
wait(1)
end
hit.Parent.Humanoid.Health -= 500
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
end
end
end)
I have time for one more reply make sure to add a check to check if the player is still touching the part
Ok I will try finding out how linking back to cooldowns:
OPEN GUI with a PART - Roblox Scripting Tutorial - YouTube
Use touchended and have variable called touching when the player touches set touching to true when touchended set touching to false
Yes.
Fixed the stacked issue:
However I am still confused on how to detect when players are no longer on the part, so if anyone can help me detect when users are off the part then end the kill script, that would be appreciated. Unless I need to revert back to the singular typing out and detected if p is false?
local debounce = true
local par = script.Parent
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
if debounce and hit.Parent:FindFirstChildWhichIsA("Humanoid") then
debounce = false
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
wait(1)
end
hit.Parent.Humanoid.Health -= 500
wait(1)
debounce = true
ui.Visible = false
else debounce = true
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
ui.Visible = false
end
end
end
end)
So what I was saying setup a variable called touching:
local touching = false
When you touch the part set touching to true
Then setup a touch ended:
script.Parent.TouchEnded:Connect(function()
touching = false
end)
Then in the loop in the touched event add a check to check if touching is false
So:
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
if not touching then break end
wait(1)
end
Final:
local touching = false
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
touching = true
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
if not touching then break end
wait(1)
end
hit.Parent.Humanoid.Health -= 500
ui.Visible = false
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
ui.Visible = false
end
end
end
end)
script.Parent.TouchEnded:Connect(function()
touching = false
end)
I mean I made one called ‘debounce’ instead, could I put:
script.Parent.TouchEnded:Connect(function()
touching = false
end)
Before line 2?
I’m not really sure what your asking but try what I wrote because I just edited the reply
After testing it…
local touching = false
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
if not touching then break end
wait(1)
end
hit.Parent.Humanoid.Health -= 500
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
end
end
end)
Because you never set touching to true so it immediately broke out of the loop and killed you.
Also instead of subtracting 500 from the Heath just set the health to 0
I put the new script at the end of the last post btw
So using this new script you provided:
local touching = false
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
touching = true
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
if not touching then break end
wait(1)
end
hit.Parent.Humanoid.Health -= 500
ui.Visible = false
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
ui.Visible = false
end
end
end
end)
script.Parent.TouchEnded:Connect(function()
touching = false
end)
It would appear that you die instantly after stepping off the part.
Error mess:
Also thank you so much for all the help <3 it really means a lot that you’re going the extra mile.
That’s because after we break out of the loop we kill the player. Let me think for a minute
I guess you can make a should kill variable and set it to true when the loop successfully finishes and set it to false if we break out so like this:
local touching = false
local shouldKill = false
script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local ui = p.PlayerGui.Cold.Frame
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
touching = true
ui.Visible = true
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
if not touching then
shouldKill = false
break
else
shouldKill=true
end
wait(1)
end
if shouldKill then hit.Parent.Humanoid.Health = 0 end
ui.Visible = false
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
ui.Visible = false
end
end
end
end)
script.Parent.TouchEnded:Connect(function()
touching = false
end)
It bloody works like a charm now! Thank you so much for all your help and Fakies simplified method.
This means a lot and will help me progress, I’m sorry this took like 2 hours. . <333333333