Did you do this? (Add on line 11)
Why would he want to fire it to all clients?
It shouldnât try to take the order of every player in the server. Just the one which triggered itâŚ
its just giving me an error i resolved earlier
Print shouldnât give you an error
i mean the fire all clients line
i put the print line in the script
Try just putting
print(Buttons)
And if that errors replace it with
print("yes it worked")
And check the output to make sure it printed a button or the phrase âyes it workedâ.
Make sure it is after you define the variable Buttons
i put the print(buttons) line but im not getting anything in the output
That means the event is not even connecting to the client.
I think the error is that the server script is doing FireClient but the cash register script is a server script itself and you need a local script for a remote event. The issue with that is that a LocalScript wonât run in workspace. What I suggest is changing the RemoteEvent to a BindableEvent
- Some corrections:
I tested in studio can do either
Material = Enum.Material.Neon
-- or
Material = ("Neon")
And
math.random(5)
-- is the same as
math.random(1,5)
- More corrections:
I ran the code
for i=1,10000 do if math.random(1)~=1 then print("No") end end
And I ran the code
for i=1, 10000000 do local r = math.random(1,5); if not (r==1 or r==2 or r==3 or r==4 or r==5) then print("No") end end
And it doesnât print anything.
local BloxyColaButton = script.Parent.BloxyColaButton
local BurgerButton = script.Parent.BurgerButton
local FriesButton = script.Parent.FriesButton
local PizzaButton = script.Parent.PizzaButton
local TacoButton = script.Parent.TacoButton
game.ReplicatedStorage.CustomerOrder1.OnClientEvent:Connect(function()
local Buttons = math.random(1,5)
print(Buttons)
if Buttons == 1 then
BloxyColaButton.Material = Enum.Material.Neon
end
if Buttons == 2 then
BurgerButton.Material = Enum.Material.Neon
end
if Buttons == 3 then
FriesButton.Material = Enum.Material.Neon
end
if Buttons == 4 then
PizzaButton.Material = Enum.Material.Neon
end
if Buttons == 5 then
TacoButton.Material = Enum.Material.Neon
end
end)
Heres the script tell me if its good
Now I said BindableEvent but if you use a server script it will show on all the other clients, which may be undesirable. Finally in that case you would want to move your code to a LocalScript and place it inside the PlayerScripts folder. And in the LocalScript you need to locate the cash register model in workspace.
Yeah, how didnât I catch that âŚ
Why are you sending a remote event from a server script to another server script?
Yeah thatâs fine, but you should use Fire client to send information to a Local Script. Not a server script.
This
local BloxyColaButton = script.Parent.BloxyColaButton
local BurgerButton = script.Parent.BurgerButton
local FriesButton = script.Parent.FriesButton
local PizzaButton = script.Parent.PizzaButton
local TacoButton = script.Parent.TacoButton
game.ReplicatedStorage.CustomerOrder1.OnClientEvent:Connect(function()
local Buttons = math.random(1,5)
print(Buttons)
if Buttons == 1 then
BloxyColaButton.Material = Enum.Material.Neon
end
if Buttons == 2 then
BurgerButton.Material = Enum.Material.Neon
end
if Buttons == 3 then
FriesButton.Material = Enum.Material.Neon
end
if Buttons == 4 then
PizzaButton.Material = Enum.Material.Neon
end
if Buttons == 5 then
TacoButton.Material = Enum.Material.Neon
end
end)
Will not work if itâs a server script. Make it a local script and it will work. But be aware other players wonât see the color change. Only the player which clicked on the register will see the color change.
Thank you it worked, but is there a way to make it so only one can be triggered at the time
After where you put print(Buttons) set all the buttons materials to the normal material (I assume which is Plastic or SmoothPlastic)
add debounce:
-- in LocalScript
local BloxyColaButton = script.Parent.BloxyColaButton
local BurgerButton = script.Parent.BurgerButton
local FriesButton = script.Parent.FriesButton
local PizzaButton = script.Parent.PizzaButton
local TacoButton = script.Parent.TacoButton
local ordering = false -- debounce variable
game.ReplicatedStorage.CustomerOrder1.OnClientEvent:Connect(function()
if ordering then return end -- if player is currently ordering, don't do anything by exiting the function using return
ordering = true -- set ordering to true so it will exit early if the function runs again
local Buttons = math.random(1,5)
if Buttons == 1 then
BloxyColaButton.Material = Enum.Material.Neon
end
if Buttons == 2 then
BurgerButton.Material = Enum.Material.Neon
end
if Buttons == 3 then
FriesButton.Material = Enum.Material.Neon
end
if Buttons == 4 then
PizzaButton.Material = Enum.Material.Neon
end
if Buttons == 5 then
TacoButton.Material = Enum.Material.Neon
end
end)
Okay after reviewing again there are several things to do here.
- You need to place your material changing code in a LocalScript inside of StarterPlayer.StarterPlayerScripts
- In the code, you need to locate each register you want to be watching (in workspace)
- You need to add a debounce to prevent other cash registers from acting.
- You need to take the code connected to .OnClientEvent and put in a function that takes the register as a parameter so you can use the same code for each cash register.