Area Detection cooldown + kill script

Here is the easier way. 1 script. Server Script in the part.

script.Parent.Touched:Connect(function(hit)
    local p = game.Players:GetPlayerFromCharacter(hit.Parent)
    if p 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)

1 Like

Question mark?

script.Parent.Touched:Connect(function(hit)
	local p = game.Players:GetPlayerFromCharacter(hit.Parent)
	if p 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)

Also why are we ending the script before killing the humanoid? Wouldn’t that render the countdown useless?

Attempting this script lead to the same result:

  • No errors
  • No UI appearing

Attempting this method:
local script in Cold parent

game.ReplicatedStorage.Activator.OnClientEvent:Connect(function(player)
	
end)

Server Sided Script in part

local event = game:GetService("ReplicatedStorage").Activator

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		event:FireClient(plr)
	end
end)

local script in part

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)

Ended with the same issue as above

There is an edited working script! Well it should be…

local p = game.Players.LocalPlayer
local ui = p.PlayerGui.Cold.Frame.Visible

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local StarterGui = game:GetService('StarterGui')
		StarterGui.Cold.Frame.Visible = true
		if ui == true then
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 9s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 8s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 7s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 6s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 5s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 4s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 3s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 2s"
			wait(1)
			ui.TextLabel.Text = "Dangerous area turn around! - 1s"
		end
	end
end)

This script doesn’t work because of the line 2 issue (visibility then text label)

First of all the local script shouldn’t be in the part if you read the instructions but the easy way there was something I messed up on here is the script that should work:


script.Parent.Touched:Connect(function(hit)
	local p = game.Players:GetPlayerFromCharacter(hit.Parent)
	if p 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
			hit.Parent.Humanoid.Health -= 500
		else
			ui.TextLabel.Text = "Dangerous area turn around! - 10s"
		end
	end
end)

Sorry, just move the .Visible

I edited the script!

This won’t work anyways because you are once again using starter gui

I was actually using PlayerGui, everywhere except for the part where they seemed to want StarterGui.

But since where you set the visibility to true it was using starter GUI and not player GUI so it wont affect anything.

1 Like

I have fixed that now in my script.

Looking at this It has confused me. So I’ll tell you what I’ve done so far and what script types I’m using.

Script In Part:

Local Script In Part too

This I didn’t quite understand so I made it:

game.ReplicatedStorage.Activator.OnClientEvent:Connect(function(player)
	
end)

For: image

Changing the name of scripts to make this easier to understand:
image

So the one I said is easier:

should work (and it’s only that one script you won’t need the other scripts for the easier one), does it not?

So what I was saying is remove the local script from the part and put everything except for the touched event inside of the

You got the source what wait() is going to be depricated?

Also curious on where he got that

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