So for context I’m attempting to make a cashier system (similar to the one in Work at a Pizza Place) and I’m having some trouble sending the player’s username to the server whenever he/she clicks the correct button on the menu tablet. I’ve tried multiple different “solutions” and none have seemed to have worked for me, any help would be greatly appreciated.
local tablet = game.Workspace.Cashier.Tablet
local orderValue = tablet.orderValue
local guiFrame = script.Parent.Main
local cashierEvent = game.ReplicatedStorage.Events.CashierCorrect
local player = game.Players.LocalPlayer
function clicked(whichButton)
if whichButton.Name == orderValue.Value then
cashierEvent:FireServer(player, player.Name)
else
print("INCORRECT!!!")
end
end
for _, button in ipairs(guiFrame:GetChildren()) do
button.MouseButton1Click:Connect(function()
clicked(button)
end)
end
You dont need to fire player.Name as the player already has the name
Get rid of player in the server script and player.Name as the player parameter is practically invisible in the serverscript and will always be there at least i think so
local tablet = game.Workspace.Cashier.Tablet
local orderValue = tablet.orderValue
local guiFrame = script.Parent.Main
local cashierEvent = game.ReplicatedStorage.Events.CashierCorrect
local player = game.Players.LocalPlayer
function clicked(whichButton)
if whichButton.Name == orderValue.Value then
cashierEvent:FireServer()
else
print("INCORRECT!!!")
end
end
for _, button in ipairs(guiFrame:GetChildren()) do
button.MouseButton1Click:Connect(function()
clicked(button)
end)
end
You don’t need to send the player when firing to the server. The server receives the player as its first argument automatically. Also, just access the name of the player on the server.
local tablet = game.Workspace.Cashier.Tablet
local orderValue = tablet.orderValue
local guiFrame = script.Parent.Main
local cashierEvent = game.ReplicatedStorage.Events.CashierCorrect
local player = game.Players.LocalPlayer
function clicked(whichButton)
if whichButton.Name == orderValue.Value then
cashierEvent:FireServer() -- no need to send player object as it is done automatically
else
print("INCORRECT!!!")
end
end
for _, button in ipairs(guiFrame:GetChildren()) do
button.MouseButton1Click:Connect(function()
clicked(button)
end)
end
The first thing that comes to the server is the player who sent this message. Also, there is an error in the client script. You shouldn’t specify who sends the event; instead, add variables directly
cashierEvent:FireServer(player.Name)
If we’re talking about the complete view, it should be like this
local tablet = game.Workspace.Cashier.Tablet
local orderValue = tablet.orderValue
local guiFrame = script.Parent.Main
local cashierEvent = game.ReplicatedStorage.Events.CashierCorrect
local player = game.Players.LocalPlayer
function clicked(whichButton)
if whichButton.Name == orderValue.Value then
cashierEvent:FireServer(player.Name)
else
print("INCORRECT!!!")
end
end
for _, button in ipairs(guiFrame:GetChildren()) do
button.MouseButton1Click:Connect(function()
clicked(button)
end)
end
Thanks for also trying to help, however this hasn’t seemed to have worked. I could possibly make this a model so you can take a more in-depth look if you would like?
After the loop, the script doesn’t continue its execution until the loop is finished
local chatService = game:GetService("Chat")
local customer = script.Parent.Customer
local orderValue = script.Parent.Tablet.orderValue
local cashierEvent = game.ReplicatedStorage.Events.CashierCorrect
local orderChoice
cashierEvent.OnServerEvent:Connect(function(Player)
print("Evenmt")
end)
while task.wait(5) do
orderChoice = math.random(1, 4)
local function numberToString()
if orderChoice == 1 then
orderChoice = "Drink"
elseif orderChoice == 2 then
orderChoice = "Burger"
elseif orderChoice == 3 then
orderChoice = "Chips"
elseif orderChoice == 4 then
orderChoice = "Pizza"
end
orderValue.Value = orderChoice
end
numberToString()
chatService:Chat(customer.Head, orderChoice)
end
Inside ServerScriptService create a new script add this inside the script:"
-- Define the event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local eventFolder = ReplicatedStorage:WaitForChild("Events") -- Replace "FolderName" with the actual name of the folder
local cashierEvent = eventFolder:WaitForChild("CashierCorrect")
-- Function to handle the event
local function handleCashierEvent(player)
print("Cashier event fired for player: " .. player.Name)
end
-- Connect the event to the handling function
cashierEvent.OnServerEvent:Connect(handleCashierEvent)
Thank you soo much! Any idea why none of the other solutions worked? From my point of view this seems like a very random fix and doesn’t really explain why all the other suggestions didn’t work, although I guess Roblox is random like that sometimes. Anyway thank you very much for fixing this issue!
Is not a random fix. You need a server script to handle a remoteEvent. You can’t just create a remote event. Every remote event must be handled by a server script. You did not have a server script in your game, nothing would work until you created the server script and wrote the code to handle the remote event.
About the other solutions they did not reference the RemoteEvent folder correctly. They did not know you used a folder for your remote event.
I was using a server script to originally handle the remote event (the one in Workspace) and all the other responses did correctly recognize the RemoteEvent was in a folder and correctly referenced it.