Trigerring script does not work

I tried to create a part where if we touch it it makes the flag turn blue after 5 seconds but this error is coming

script:

local Trigger = script.Parent

local Flag = script.Parent.Parent.Flag

local Pole = script.Parent.Parent.Pole

local cooldown = false

Trigger.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if hit.Parent:FindFirstChild('Humanoid') then
		if cooldown == true then
			
			wait(5)
			
			Flag.BrickColor.new = BrickColor.new('Baby blue')
			
		elseif cooldown == false then
			Flag.BrickColor.new = BrickColor.new('Really red')
			
		end
	end
end)

This is the error:


What seems to be the problem?

Flag.BrickColor.new is not a property of BrickColor, though it is a method of the BrickColor API:

local Trigger = script.Parent

local Flag = script.Parent.Parent.Flag

local Pole = script.Parent.Parent.Pole

local cooldown = false

Trigger.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if hit.Parent:FindFirstChild('Humanoid') then
		if cooldown == true then
			
			wait(5)
			
			Flag.BrickColor = BrickColor.new('Baby blue')
			
		elseif cooldown == false then
			Flag.BrickColor = BrickColor.new('Really red')
			
		end
	end
end)

Just remove the .new and it should work.

When you see the error ’ cannot be assigned to’, that means is a read only property, or it doesn’t exist.

1 Like

So should the script be:

local Trigger = script.Parent

local Flag = script.Parent.Parent.Flag

local Pole = script.Parent.Parent.Pole

local cooldown = false

Trigger.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if hit.Parent:FindFirstChild('Humanoid') then
		if cooldown == true then
			
			wait(5)
			
			Flag.BrickColor = BrickColor('Baby blue')
			
		elseif cooldown == false then
			Flag.BrickColor= BrickColor('Really red')
			
		end
	end
end)

Right?

1 Like

Yeah, but do not use wait(), it’s deprecated and overall worse than task.wait(). Look at the task library announcement topic to understand why. Even if you don’t, just use task.wait() over wait().

Ok I will use that but it will get the job done

So what I tried to create is that when the player stands on the part the script will trigger and it should check whether the player is standing for 5 seconds or not

If they are the flag turns blue

1 Like

task.wait() and wait() will do the same thing, but task.wait() does it better, so your script should still work. I have to leave very soon so if it doesn’t then I won’t be able to help you.

ok no problem and appreciate for the help.

Yeah, to be exact, task.wait() is much more accurate and if you use it without any set time, it’s much faster. It’s the same as RunService.Heartbeat:Wait().

1 Like

That’s the big reason to use task.wait(), though I think task.wakt() has better memory usage than wait(), or I am just confusing that with another Roblox method.

EDIT: I am probably mixing up the sleep (task.wait() and wait()) methods with the time method, e.g. tick(), os.time(), and (my favorite) os.clock() since some of them have better memory usage than other ones.

1 Like

The difference is only really significant when calling with no arguments inside of a loop.

task.wait() --1 frame
wait() --2 frames

Yeah. task.wait() also respects FPS over 60, so if you’re using a FPS unlocker, it’s gonna wait even faster. But task.wait(1) is actually more accurate than wait(1). Anyways, let’s not go too off-topic.

Isn’t FPS unlocking only available through exploits?

No… Haven’t you heard about rbxfpsunlocker? Roblox even approved it to be allowed themselves.

Mind linking the post where it was allowed by an official Roblox representative?

There’s no post as far as I know, but they’ve said it somewhere, could have been some RDC (I have no idea.), and there’s no confirmed ban on anyone using rbxfpsunlocker.

Right, that’s a little different from.

Roblox even approved it to be allowed themselves.

local Trigger = script.Parent
local Flag = script.Parent.Parent.Flag
local Pole = script.Parent.Parent.Pole

local debounce = false
local toggle = false

Trigger.Touched:Connect(function(hit)
	if debounce then
		return
	end
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		debounce = true
		if toggle then
			toggle = false
			Flag.BrickColor = BrickColor.new('Baby blue')
			task.wait(5)
			debounce = false
		elseif not toggle then
			toggle = true
			Flag.BrickColor= BrickColor.new('Really red')
			task.wait(5)
			debounce = false
		end
	end
end)

Let me know if this works as you intended.

1 Like

But actually did not work so any other commands?