-
What do you want to achieve? I am making a :place command that will teleport players to another game, for example “:place all 123456789”
-
What is the issue? When the player sends the command for first time, then it will work perfectly. But it won’t run back again (there’s a remote event to fire it)
-
What solutions have you tried so far? I tried replacing the lines with a function and a while loop to do it, however it’s still not working.
player.Chatted:Connect(function(message)
if module:Command(message,command) and module.GameId(message,command) then
local gameId = module.GameId(message,command)
player.PlayerGui.AgreeGui.Enabled = true
remote.OnServerEvent:Wait()
if module:PlayerOnGroup(player) and module:PlayerOnRank(player) then
module:TeleportPlayers(gameId)
I used a print statement after and it’s not printing it twice. The modules work perfectly, it’s just the event here.
The gui doesn’t appears visible either, so it must be something with the.Chatted event
Are you using module scripts? Because I would recommend a regular script and use a BindableFunction.
Yes, the script does work, the only problem here is that the event is not running twice. I am returning the values in the functions at the modules so I don’t need to use a BindableFunction.
What’s this for? (30 charssss)
.OnServerEvent is what the name says, an event, if you want to run code through it more than once, you have to connect it to a function, that’s why people use:
RemoteEvent.OnServerEvent:Connect(function(Player)
--do stuff
end)
or:
local function functionName(Player)
--do stuff
end
RemoteEvent.OnServerEvent:Connect(functionName)
Now a RemoteEvent is an Event that you have to connect to a function, but a RemoteFunction is already a function that’s why you do:
RemoteFunction.OnServerInvoke = function(Player)
--do stuff
end
Or:
local function functionName(Player)
--do stuff
end
RemoteFunction.OnServerInvoke = functionName
It waits for the remote to fire, and when it does then it continues the lines after it. I used the other way short after but it didn’t work out.
I tried using a RemoteFunction and it didn’t work. There is a button that appears when you write the command where you have to agree or disagree, however, if the teleport fails or the player clicks disagree then it will keep waiting for the function to fire and never plays again. That’s my problem, not the module or the functions.