Goal: Attempting to make it so, when you are touching certain parts in a folder you get a UI saying “Dangerous area turn around! - 10s” Then after 10 seconds it kills you. - So you are in an ‘area part’ and if you stay in it when the text label says 1s you get killed, but if you leave the area the ui sets back to 10s and become invisible. (visible = false)
local p = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local ui = p.PlayerGui.Cold.Frame
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
wait(1)
end
p.Humanoid.Health -= 500
else
ui.TextLabel.Text = "Dangerous area turn around! - 10s"
end
end
end)
One more question is this a local or server script.
My bad change player to p and remove the then. I edited the script so now it should actually work (sorry about the mistakes written on mobile!) so try out the new script
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
local ui = p:WaitForChild("PlayerGui").Cold.Frame -- LINE 4
if ui.Visible == true then
for i = 10, 1, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - " .. i .."s"
wait(1)
end
hit.Parent.Humanoid = hit.Parent.Humanoid - 500
elseif ui == false then
game.StarterGui.Cold.Frame.TextLabel.Text = "Dangerous area turn around! - 10s"
end
end
end)
Going off what Zayd and you have said so far I’ve got this:
local p = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local ui = p.PlayerGui.Cold.Frame
if ui.Visible then
for i = 10, 0, -1 do
ui.TextLabel.Text = "Dangerous area turn around! - "..i.."s"
wait(1)
end
p.Humanoid.Health -= 500
else
game.StarterGui.Cold.Frame.TextLabel.Text = "Dangerous area turn around! - 10s"
end
end
end)
So now we need to fire a remote event that does what we need to do now?
Make a remote event in ReplicatedStorage (for example named showUi)
Add a Local Script in StarterGui (basically the same script but instead of the touched event put it in a game.ReplicatedStorage.showUi.OnClientEvent:Connect(function(player)
In your part make a Script (server) and put this in it:
local event = game:GetService("ReplicatedStorage").showUi
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
event:FireClient(plr)
end
end)