How would I make this server script wait until the player clicks after chatting to do a function?
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Message == "Flame!" or "flame!" or "Flame" or "flame" then
local player = game.Players:WaitForChild(Player.Name)
local m = player:GetMouse()
m.Button1Down:Connect(function()
print("Clicked!")
end)
end
end)
end)
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Message == "Flame!" or Message == "flame!" or Message == "Flame" or Message == "flame" then
local m = Player:GetMouse()
m.Button1Down:Connect(function()
print("Clicked!")
end)
end
end)
end)
Local script, place it inside StarterPlayerScripts folder.
That could be your problem right there. Try moving this to a LocalScript in StarterGui and see what happens. Just remove the first function and add a local player function. Try this and see if it works:
local Player = game.Players.LocalPlayer
Player.Chatted:Connect(function(Message)
if string.lower(Message) == "flame!" or string.lower(Message) == "flame" then
local player = game.Players:WaitForChild(Player.Name)
local m = player:GetMouse()
m.Button1Down:Connect(function()
print("Clicked!")
end)
end
end)
local Player = game.Players.LocalPlayer
local Used = false
local Mouse = Player:GetMouse()
Player.Chatted:Connect(function(Message)
if string.lower(Message) == "flame!" or string.lower(Message) == "flame!" then
Used = true
end
end)
Mouse.Button1Down:Connect(function()
if Used == true then
print("Clicked!")
Used = false
end
end)
This still wonât work, you canât check multiple conditions like that.
local debounce = false
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Message == "Flame!" or Message == "flame!" or Message == "Flame" or Message == "flame" then
local m = Player:GetMouse()
m.Button1Down:Connect(function()
if not debounce then
print("Clicked!")
debounce = true
end
end)
end
end)
end)
This will make it so that the print(âClicked!â) command will only execute once. Even if someone chats âflameâ or âflame!â etc.
Alright, try this (after editing it a few times I think this should work)
local Player = game.Players.LocalPlayer
local Used = false
local Mouse = Player:GetMouse()
Player.Chatted:Connect(function(Message)
if string.lower(Message) == "flame!" or string.lower(Message) == "flame!" then
Used = true
end
end)
Mouse.Button1Down:Connect(function()
if Used == true then
print("Clicked!")
Used = false
end
end)
Wrong, player is referring to the player, he is just using Player.Name for WaitForChild, which returns the child and NOT its name.
Youâll use the disconnect function, but you have to disconnect a connection (obviously), so it would look something like this:
local Player = game.Players.LocalPlayer
local function Chatted(Message, connection)
if Message == "Flame!" or "flame!" or "Flame" or "flame" then
local m = Player:GetMouse()
m.Button1Down:Connect(function()
print("Clicked!")
end)
connection:Disconnect()
end
local connection = Player.Chatted:Connect(Chatted(message, connection)