Making A Simple Simulator game on roblox and im using remote events to buy tools for cash (or as i refer to it as "Halopower" )
and the button detects its being clicked but does not fire the event OR the server script does not pick it up
local script firing it:
local btnText = script.Parent.TextLabel local btn = script.Parent local repStorage = game:GetService("ReplicatedStorage") btn.MouseButton1Click:Connect(function() repStorage.Remotes.BuyMolten:FireServer() end)
server script "suppose to be" detecting it
local ReplicatedStorage = game:GetService('ReplicatedStorage') local remoteEvent = ReplicatedStorage:WaitForChild("BuyMolten") local btnText = game.Players:WaitForChild("PlayerGui").ShopUI.Frame.BuyMolten.TextLabel.Text local toolFolder = game.ServerStorage.ShopItems local toolPrice = 150 remoteEvent.OnServerEvent:Connect(function(player) print("FireServerDetectedFromBuyTool") if player.leaderstats.Halopower.Value >= toolPrice then player.leaderstats.Halopower.Value = player.leaderstats.Halopower - toolPrice toolFolder:FindFirstChild("Molten Halo"):Clone().Parent = player.Backpack end end)
if needed i will include code from other parts of the game like data stores remotes stats and more.
thanks, Joe Engo (aka MightBeAHaxxer / MightBeAScripter)
Hello MightBeAHaxxer!
Though I am not exactly sure what is wrong due to the lack of information, I believe it is from one of these issues;
A) The ServerScript is somewhere the server cannot access.
B) The LocalScript is somewhere the player cannot access.
C) The button is not a textbutton.
In of a TextButton, you should insert a local script! The contents of the localscript should be whats below.
local button = script.Parent --The TextButton object local repStorage = game:GetService('ReplicatedStorage') local buyMolten = repStorage:WaitForChild('Remotes'):WaitForChild('BuyMolten') button.MouseButton1Click:Connect(function() print('Owch! That click hurt!') buyMolten:FireServer() print('All you had to do was ask :(') end)
Now, inside of a regular Script (not local) inside of ServerScriptService the contentsshould be as follows.
local repStorage = game:GetService('ReplicatedStorage') local buyMolten = repStorage:WaitForChild('Remotes'):WaitForChild('BuyMolten') buyMolten.OnServerEvent:Connect(function(PlayerObject) print('Well we heard that one!') end)
Therefore, when you press the TextButton the output should be as follows:
Owch! That click hurt!
All you had to do was ask :(
Well we heard that one!