I made this script so when a specific button i pressed, i gives money.( If need context here it is: a proximity prompt is triggered from an npc. When the Proximity Prompt is triggered, a script in ServerScriptService will Trigger a remote event in Replicated Storage. When the remote event will be triggered, a cash register in workspace will receive the triggered event (a script in the cash register)
When the remote event is received, the script will randomly choose a button on the cash register and will make it become neon.
So right now im at the part where im making the script that gives you money when the player presses the neon button. I finished righting the script, there aren’t any mistakes in it (no errors appear). but when i test it, nothing happens, and i still get no errors in the output. if you now a fix, pls tell me.
heres the code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local OrderBloxyColaEvent = ReplicatedStorage:WaitForChild("OrderBloxyCola")
local OrderPizzaEvent = ReplicatedStorage:WaitForChild("OrderPizza")
local OrderBurgerEvent = ReplicatedStorage:WaitForChild("OrderBurger")
local OrderFriesEvent = ReplicatedStorage:WaitForChild("OrderFries")
local OrderTacoEvent= ReplicatedStorage:WaitForChild("OrderTaco")
-------------------------------------------------------------------------
local BloxyColaButton = Workspace.CashRegister1.BloxyColaButton
local BurgerButton = Workspace.CashRegister1.BurgerButton
local FriesButton = Workspace.CashRegister1.FriesButton
local PizzaButton = Workspace.CashRegister1.PizzaButton
local TacoButton = Workspace.CashRegister1.TacoButton
-------------------------------------------------------------------------
local BloxyColaImageButton = Workspace.CashRegister1.BloxyColaButton.SurfaceGui.BloxyCola
local BurgerImageButton = Workspace.CashRegister1.BurgerButton.SurfaceGui.Burger
local PizzaImageButton = Workspace.CashRegister1.PizzaButton.SurfaceGui.Pizza
local TacoImageButton = Workspace.CashRegister1.TacoButton.SurfaceGui.Taco
local FriesImageButton = Workspace.CashRegister1.FriesButton.SurfaceGui.Fries
-------------------------------------------------------------------------
local Player = game.Players.LocalPlayer
local Money = Player:WaitForChild('leaderstats'):WaitForChild('Money')
-------------------------------------------------------------------------
OrderBloxyColaEvent.OnClientEvent:Connect(function(PlayerWhoClicked)
function OnClicked1(PlayerWhoClicked)
Money.Value = Money.Value + 3
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
BloxyColaButton.Material = ("Plastic")
end
end)
OrderTacoEvent.OnClientEvent:Connect(function(PlayerWhoClicked)
function OnClicked2(PlayerWhoClicked)
Money.Value = Money.Value + 3
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
TacoButton.Material = ("Plastic")
end
end)
OrderFriesEvent.OnClientEvent:Connect(function(PlayerWhoClicked)
function OnClicked3(PlayerWhoClicked)
Money.Value = Money.Value + 3
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
FriesButton.Material = ("Plastic")
end
end)
OrderBurgerEvent.OnClientEvent:Connect(function(PlayerWhoClicked)
function OnClicked4(PlayerWhoClicked)
Money.Value = Money.Value + 3
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
BurgerButton.Material = ("Plastic")
end
end)
OrderPizzaEvent.OnClientEvent:Connect(function(PlayerWhoClicked)
function OnClicked5(PlayerWhoClicked)
Money.Value = Money.Value + 3
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
PizzaButton.Material = ("Plastic")
end
end)
BloxyColaButton.ClickDetector.MouseClick:Connect(OnClicked1)
TacoButton.ClickDetector.MouseClick:Connect(OnClicked2)
FriesButton.ClickDetector.MouseClick:Connect(OnClicked3)
BurgerButton.ClickDetector.MouseClick:Connect(OnClicked4)
PizzaButton.ClickDetector.MouseClick:Connect(OnClicked5) ```
Jeez there are so many things wrong here. First off, why are you making OnClick functions inside a remote event???
It should look a bit more like this:
local Workspace = game:GetService("Workspace")
local OrderBloxyColaEvent = ReplicatedStorage:WaitForChild("OrderBloxyCola")
local OrderPizzaEvent = ReplicatedStorage:WaitForChild("OrderPizza")
local OrderBurgerEvent = ReplicatedStorage:WaitForChild("OrderBurger")
local OrderFriesEvent = ReplicatedStorage:WaitForChild("OrderFries")
local OrderTacoEvent= ReplicatedStorage:WaitForChild("OrderTaco")
-------------------------------------------------------------------------
local BloxyColaButton = Workspace.CashRegister1.BloxyColaButton
local BurgerButton = Workspace.CashRegister1.BurgerButton
local FriesButton = Workspace.CashRegister1.FriesButton
local PizzaButton = Workspace.CashRegister1.PizzaButton
local TacoButton = Workspace.CashRegister1.TacoButton
-------------------------------------------------------------------------
local BloxyColaImageButton = Workspace.CashRegister1.BloxyColaButton.SurfaceGui.BloxyCola
local BurgerImageButton = Workspace.CashRegister1.BurgerButton.SurfaceGui.Burger
local PizzaImageButton = Workspace.CashRegister1.PizzaButton.SurfaceGui.Pizza
local TacoImageButton = Workspace.CashRegister1.TacoButton.SurfaceGui.Taco
local FriesImageButton = Workspace.CashRegister1.FriesButton.SurfaceGui.Fries
-------------------------------------------------------------------------
local function OnClick(Player)
local stats = Player.leaderstats
local Money = stats.Money
Money.Value += 3
end
BloxyColaButton.ClickDetector.MouseClick:Connect(function()
OnClick()
BloxyColaButton.Material = Enum.Material.Plastic
end)
TacoButton.ClickDetector.MouseClick:Connect(function()
OnClick()
TacoButton.Material = Enum.Material.Plastic
end)
FriesButton.ClickDetector.MouseClick:Connect(function()
OnClick()
FriesButton.Material = Enum.Material.Plastic
end)
BurgerButton.ClickDetector.MouseClick:Connect(function()
OnClick()
BurgerButton.Material = Enum.Material.Plastic
end)
PizzaButton.ClickDetector.MouseClick:Connect(function()
OnClick()
PizzaButton.Material = Enum.Material.Plastic
end)
Another thing that is completely wrong and not sure how/why you didn’t get an error, you tried to use local player in a regular script, which you can’t do
the remote functions are there for a reason. when it gets, triggered, the player needs to click a specific button to get money, the player cant be able too click buttons and get money.
I found a way to make the script wor, if i have no mistake. Now i just need help adding a line that give the player money when the button is clicked
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Teams = game:GetService("Teams")
------------------------------------------------------------------------- Remote Functions
local OrderBloxyColaEvent = ReplicatedStorage:WaitForChild("OrderBloxyCola")
local OrderPizzaEvent = ReplicatedStorage:WaitForChild("OrderPizza")
local OrderBurgerEvent = ReplicatedStorage:WaitForChild("OrderBurger")
local OrderFriesEvent = ReplicatedStorage:WaitForChild("OrderFries")
local OrderTacoEvent= ReplicatedStorage:WaitForChild("OrderTaco")
------------------------------------------------------------------------- Cash Register Buttons
local BloxyColaButton = Workspace.CashRegister1.BloxyColaButton
local BurgerButton = Workspace.CashRegister1.BurgerButton
local FriesButton = Workspace.CashRegister1.FriesButton
local PizzaButton = Workspace.CashRegister1.PizzaButton
local TacoButton = Workspace.CashRegister1.TacoButton
------------------------------------------------------------------------- Player and leaderstats
local Player = game.Players.LocalPlayer
local Money = Player:WaitForChild('leaderstats'):WaitForChild('Money')
------------------------------------------------------------------------- Button can give money
local BloxyColaMoney = false
local TacoMoney = false
local FriesMoney = false
local BurgerMoney = false
local PizzaMoney = false
local PlayerWhoClickedIsCashier = false
OrderBloxyColaEvent.OnClientEvent:Connect(function()
BloxyColaMoney = true
end)
OrderTacoEvent.OnClientEvent:Connect(function()
TacoMoney = true
end)
OrderFriesEvent.OnClientEvent:Connect(function()
FriesMoney = true
end)
OrderBurgerEvent.OnClientEvent:Connect(function()
BurgerMoney = true
end)
OrderPizzaEvent.OnClientEvent:Connect(function()
PizzaMoney = true
end)
-------------------------------------------------------------------------
function OnClicked1(Player)
if Player.Team.Name == "Cashier" then
PlayerWhoClickedIsCashier = true
if BloxyColaMoney + PlayerWhoClickedIsCashier == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
BloxyColaButton.Material = ("Plastic")
PlayerWhoClickedIsCashier = false
BloxyColaMoney = false
elseif Player.Team.Name ~= "Cashier" then
print("Player can't take order, he isn't working here")
elseif BloxyColaMoney ~= false then
print("No order, can't press buttons")
end
end
end
function OnClicked2(Player)
if Player.Team.Name == "Cashier" then
PlayerWhoClickedIsCashier = true
if TacoMoney + PlayerWhoClickedIsCashier == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
TacoButton.Material = ("Plastic")
PlayerWhoClickedIsCashier = false
TacoMoney = false
elseif Player.Team.Name ~= "Cashier" then
print("Player can't take order, he isn't working here")
elseif TacoMoney ~= false then
print("No order, can't press buttons")
end
end
end
function OnClicked3(Player)
if Player.Team.Name == "Cashier" then
PlayerWhoClickedIsCashier = true
if FriesMoney + PlayerWhoClickedIsCashier == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
FriesButton.Material = ("Plastic")
PlayerWhoClickedIsCashier = false
FriesMoney = false
elseif Player.Team.Name ~= "Cashier" then
print("Player can't take order, he isn't working here")
elseif FriesMoney ~= false then
print("No order, can't press buttons")
end
end
end
function OnClicked4(Player)
if Player.Team.Name == "Cashier" then
PlayerWhoClickedIsCashier = true
if BurgerButton + PlayerWhoClickedIsCashier == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
BurgerButton.Material = ("Plastic")
PlayerWhoClickedIsCashier = false
BurgerMoney = false
elseif Player.Team.Name ~= "Cashier" then
print("Player can't take order, he isn't working here")
elseif BurgerMoney ~= false then
print("No order, can't press buttons")
end
end
end
function OnClicked5(Player)
if Player.Team.Name == "Cashier" then
PlayerWhoClickedIsCashier = true
if PizzaMoney + PlayerWhoClickedIsCashier == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
PizzaButton.Material = ("Plastic")
PlayerWhoClickedIsCashier = false
PizzaMoney = false
elseif Player.Team.Name ~= "Cashier" then
print("Player can't take order, he isn't working here")
elseif PizzaMoney ~= false then
print("No order, can't press buttons")
end
end
end
BloxyColaButton.ClickDetector.MouseClick:Connect(OnClicked1)
TacoButton.ClickDetector.MouseClick:Connect(OnClicked2)
FriesButton.ClickDetector.MouseClick:Connect(OnClicked3)
BurgerButton.ClickDetector.MouseClick:Connect(OnClicked4)
PizzaButton.ClickDetector.MouseClick:Connect(OnClicked5)
It looks like you are trying to change the value of the Money leaderstat when the player clicks on one of the neon buttons on the cash register. However, it appears that you are not actually connecting any event handlers to the buttons to detect when they are clicked.
To fix this issue, you’ll need to add event handlers to the buttons to detect when they are clicked. Here’s an example of how you might do this:
This will connect event handlers to each button that will run the corresponding OnClicked function when the button is clicked.
Additionally, you may want to consider using the BindableEvent object to send events between the server and the client, rather than using RemoteEvent objects. This can make it easier to trigger events and pass arguments between the server and the client.
------------------------------------------------------------------------- Game Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Teams = game:GetService("Teams")
------------------------------------------------------------------------- Remote Functions
local OrderBloxyColaEvent = ReplicatedStorage:WaitForChild("OrderBloxyCola")
local OrderPizzaEvent = ReplicatedStorage:WaitForChild("OrderPizza")
local OrderBurgerEvent = ReplicatedStorage:WaitForChild("OrderBurger")
local OrderFriesEvent = ReplicatedStorage:WaitForChild("OrderFries")
local OrderTacoEvent= ReplicatedStorage:WaitForChild("OrderTaco")
------------------------------------------------------------------------- Cash Register Buttons
local BloxyColaButton = Workspace.CashRegister1.BloxyColaButton
local BurgerButton = Workspace.CashRegister1.BurgerButton
local FriesButton = Workspace.CashRegister1.FriesButton
local PizzaButton = Workspace.CashRegister1.PizzaButton
local TacoButton = Workspace.CashRegister1.TacoButton
------------------------------------------------------------------------- Player and leaderstats
local Player = game.Players.LocalPlayer
------------------------------------------------------------------------- Button can give money
local BloxyColaMoney = false
local TacoMoney = false
local FriesMoney = false
local BurgerMoney = false
local PizzaMoney = false
local PlayerWhoClickedIsCashier = false
OrderBloxyColaEvent.OnClientEvent:Connect(function()
BloxyColaMoney = true
end)
OrderTacoEvent.OnClientEvent:Connect(function()
TacoMoney = true
end)
OrderFriesEvent.OnClientEvent:Connect(function()
FriesMoney = true
end)
OrderBurgerEvent.OnClientEvent:Connect(function()
BurgerMoney = true
end)
OrderPizzaEvent.OnClientEvent:Connect(function()
PizzaMoney = true
end)
-------------------------------------------------------------------------
BloxyColaButton.MouseButton1Click:Connect(function()
function OnClicked1(Player)
if BloxyColaMoney == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
BloxyColaButton.Material = ("Plastic")
BloxyColaMoney = false
elseif BloxyColaMoney ~= false then
print("No order, can't press buttons")
end
end
end)
TacoButton.MouseButton1Click:Connect(function()
function OnClicked2(Player)
if TacoMoney == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
TacoButton.Material = ("Plastic")
TacoMoney = false
elseif TacoMoney ~= false then
print("No order, can't press buttons")
end
end
end)
FriesButton.MouseButton1Click:Connect(function()
function OnClicked3(Player)
if FriesMoney == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
FriesButton.Material = ("Plastic")
FriesMoney = false
elseif FriesMoney ~= false then
print("No order, can't press buttons")
end
end
end)
BurgerButton.MouseButton1Click:Connect(function()
function OnClicked4(Player)
if BurgerButton == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
BurgerButton.Material = ("Plastic")
BurgerMoney = false
elseif BurgerMoney ~= false then
print("No order, can't press buttons")
end
end
end)
PizzaButton.MouseButton1Click:Connect(function()
function OnClicked5(Player)
if PizzaMoney == true then
Workspace.Customer1.Torso.ProximityPrompt.Enabled = true
PizzaButton.Material = ("Plastic")
PizzaMoney = false
elseif PizzaMoney ~= false then
print("No order, can't press buttons")
end
end
end)
BloxyColaButton.ClickDetector.MouseClick:Connect(OnClicked1)
TacoButton.ClickDetector.MouseClick:Connect(OnClicked2)
FriesButton.ClickDetector.MouseClick:Connect(OnClicked3)
BurgerButton.ClickDetector.MouseClick:Connect(OnClicked4)
PizzaButton.ClickDetector.MouseClick:Connect(OnClicked5)
Once again, why did you put the OnClick function inside another event, one that in this case doesn’t even exist. Please revert back to your original script and then make the adjustments I told you to
I applied your fixes, it works but there one problem. The material doesnt change when you click it. and also i added while true do, but when the remote event is fired theres a lag spike for a second, i dont know why.
Heres the script
------------------------------------------------------------------------- Game Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Teams = game:GetService("Teams")
------------------------------------------------------------------------- Remote Functions
local OrderBloxyColaEvent = ReplicatedStorage:WaitForChild("OrderBloxyCola")
local OrderPizzaEvent = ReplicatedStorage:WaitForChild("OrderPizza")
local OrderBurgerEvent = ReplicatedStorage:WaitForChild("OrderBurger")
local OrderFriesEvent = ReplicatedStorage:WaitForChild("OrderFries")
local OrderTacoEvent= ReplicatedStorage:WaitForChild("OrderTaco")
------------------------------------------------------------------------- Cash Register Buttons
local BloxyColaButton = Workspace.CashRegister1.BloxyColaButton
local BurgerButton = Workspace.CashRegister1.BurgerButton
local FriesButton = Workspace.CashRegister1.FriesButton
local PizzaButton = Workspace.CashRegister1.PizzaButton
local TacoButton = Workspace.CashRegister1.TacoButton
local ProximityPrompt = workspace.Customer1.Torso.ProximityPrompt
------------------------------------------------------------------------- Player and leaderstats
local Player = game.Players.LocalPlayer
------------------------------------------------------------------------- Button can give money
local BloxyColaMoney = false
local TacoMoney = false
local FriesMoney = false
local BurgerMoney = false
local PizzaMoney = false
local PlayerWhoClickedIsCashier = false
-------------------------------------------------------------------------
function OnClicked1(Player)
if BloxyColaMoney == true then
print("It Works")
ProximityPrompt.Enabled = true
BloxyColaButton.Material = Enum.Material.Plastic
BloxyColaMoney = false
elseif BloxyColaMoney ~= true then
print("Order not placed")
end
end
function OnClicked2(Player)
if TacoMoney == true then
print("It Works")
ProximityPrompt.Enabled = true
TacoButton.Material = Enum.Material.Plastic
TacoMoney = false
elseif BloxyColaMoney ~= true then
print("Order not placed")
end
end
function OnClicked3(Player)
if FriesMoney == true then
print("It Works")
ProximityPrompt.Enabled = true
FriesButton.Material = Enum.Material.Plastic
FriesMoney = false
elseif BloxyColaMoney ~= true then
print("Order not placed")
end
end
function OnClicked4(Player)
if BurgerMoney == true then
print("It Works")
ProximityPrompt.Enabled = true
BurgerButton.Material = Enum.Material.Plastic
BurgerMoney = false
elseif BloxyColaMoney ~= true then
print("Order not placed")
end
end
function OnClicked5(Player)
if PizzaMoney == true then
print("It Works")
ProximityPrompt.Enabled = true
PizzaButton.Material = Enum.Material.Plastic
PizzaMoney = false
elseif BloxyColaMoney ~= true then
print("Order not placed")
end
end
BloxyColaButton.ClickDetector.MouseClick:Connect(OnClicked1)
TacoButton.ClickDetector.MouseClick:Connect(OnClicked2)
FriesButton.ClickDetector.MouseClick:Connect(OnClicked3)
BurgerButton.ClickDetector.MouseClick:Connect(OnClicked4)
PizzaButton.ClickDetector.MouseClick:Connect(OnClicked5)
while true do
OrderBloxyColaEvent.OnServerEvent:Connect(function()
BloxyColaMoney = true
end)
OrderTacoEvent.OnServerEvent:Connect(function()
TacoMoney = true
end)
OrderFriesEvent.OnServerEvent:Connect(function()
FriesMoney = true
end)
OrderBurgerEvent.OnServerEvent:Connect(function()
BurgerMoney = true
end)
OrderPizzaEvent.OnServerEvent:Connect(function()
PizzaMoney = true
end)
end