#Running a remote Event from a button click in a gui
1 messages · Page 1 of 1 (latest)
once the button is clicked, im pretty sure you know how to do that
make sure you have a variable to the remote event
now do
RemoteEventVar:FireServer(arg, ...)
you dont need the "arg" but it depends on you.
i did all this and i got nothing back on the connection side
** You are now Level 12! **
i thought i was doing it wrong
did you call
RemoteEventVar.OnServerEvent:Connect(...) on the server side?
is this a
Client -> Server
or a
Server -> Client
or
Server -> Server
or
Client -> Client
im just assumping that this is a
Client -> Server
since its a gui
so in StartPlayerScripts i have this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local startGameEvent = RemoteEvents:WaitForChild("StartGame")
local GameClientModule = require(ReplicatedStorage:WaitForChild("GameClientModule"))
local player = Players.LocalPlayer
startGameEvent.OnClientEvent:Connect(function()
print("RemoteEvent StartGame received")
GameClientModule.StartGame(player)
end)
what about on how you fire it?
but i dont get that print statment
this
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local gui = player:WaitForChild("PlayerGui"):WaitForChild("SinglePlayerGui")
local startGameEvent = game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("StartGame")
button.MouseButton1Click:Connect(function()
local extraData = player:FindFirstChild("extraData")
local playingGame = extraData and extraData:FindFirstChild("playingGame")
if not playingGame then
warn("Player is missing 'playingGame' BoolValue")
return
end
if not playingGame.Value then
gui.Enabled = false
print("Starting game for", player.Name)
startGameEvent:FireServer(player)
playingGame.Value = true
else
print("Player already in game:", player.Name)
end
end)
which is a local script inside startgui
this is also a local script
and on this one i get the print that it started the game
oh ok now i see
so are you firing a RemoteEvent or a BindableEvent?
okay so, your actually doing it right, but your doing it wrong aswell.
Its a Client -> Client
Remote Events are supposed to be
Client -> Server
or a
Server -> Client
ohh right
use a BindableEvent
But use
:Fire and .Event
so what is the difference between a bindable and remote?
Bindable are for
Server -> Server
or
Client -> Client
Whilist Remote needs to be
Client -> Server
or a
Server -> Client
ahh right thank you
np!
pls close the post if you fixed it
onserverevent means client to server
it means you fired to server on a local script then your receiving it on a server script
Yeah..?