Just one adjustment, to a previous system

Basically I made a chatted event, went here to try and figure out how to fix it. Then some people helped, but I want to make it that when you say /tower (the command for the chatted event) the cooldown only affects to them (which is 5 seconds) and that someone else can still use the command when the cooldown is in effect for someone.

(the code is correct, i just want a change so that the text above can be implemented)
code:

local tpmessage = "/tower"
local endpart = game.Workspace.endPart
local debounce = false

endpart.CanCollide = false 

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if string.lower(msg) == tpmessage and debounce == false then
			player.Character.HumanoidRootPart.CFrame = endpart.CFrame
			debounce = true
			wait(5)
			debounce = false
        end
    end)
end)

Edit: I have to move out of my house for days, dont ask why, but responding will still help, and i will look at it in 2 days.

Here you go this should work, I basically stored the player name to a table and have the code check if the player name if it is in the table (If it is not then it can teleport). After 5 seconds the player name is removed from the table and can use the command again.

Here is the code:

local tpmessage = "/tower"
local endpart = game.Workspace.endPart

endpart.CanCollide = false 

local playertable = {}

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local playerfound = false
		
		for i,v in pairs(playertable) do
			if v == player.Name then
				playerfound = true
			end
		end
		
        if string.lower(msg) == tpmessage and playerfound == false then
			player.Character.HumanoidRootPart.CFrame = endpart.CFrame
			table.insert(playertable, 3, player.Name)
			wait(5)
			
			for i,v in pairs(playertable) do
			if v == player.Name then
				table.remove(playertable, i)
			end
		end
        end
    end)
end)
1 Like