#Running a remote Event from a button click in a gui

1 messages · Page 1 of 1 (latest)

runic void
#

So im making a minesweeper type game and i want to call a remote event in order to start the game from a button press, but im not sure how to do this?

mighty vapor
#

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.

runic void
jade coralBOT
#

studio** You are now Level 12! **studio

runic void
#

i thought i was doing it wrong

mighty vapor
#

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

runic void
# mighty vapor did you call `RemoteEventVar.OnServerEvent:Connect(...)` on the server side?

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)
mighty vapor
runic void
#

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

runic void
mighty vapor
#

oh ok now i see

mighty vapor
runic void
#

RemoteEvent

mighty vapor
# runic void

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

runic void
#

ohh right

mighty vapor
#

use a BindableEvent

runic void
#

i think its because i just changed it

#

it was a client to server before

mighty vapor
#

But use

:Fire and .Event

runic void
#

ahh okay

runic void
mighty vapor
#

Whilist Remote needs to be

Client -> Server
or a
Server -> Client

runic void
#

ahh right thank you

mighty vapor
#

np!

rocky herald
#

pls close the post if you fixed it

solar radish
#

it means you fired to server on a local script then your receiving it on a server script

mighty vapor