I have made a GUI Gear Shop for a my game, and so far added just a gravity coil, which is put in lighting for the script. I tested it out in studio and it worked greatly, then I published and tested it out in a game. But even though I had the right amount of currency it wouldn't put the item into my inventory. Could someone explain what is wrong? Heres the script.
script.Parent.MouseButton1Click:connect(function() local Lighting = game:GetService("Lighting") local item = Lighting:WaitForChild("GravityCoil") local price = 50 local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats")
if stats.Money.Value >= price then stats.Money.Value = stats.Money.Value - price local cloned = item:Clone() local cloned2 = item:Clone() cloned2.Parent = player.Backpack cloned.Parent = player.StarterGear end end)
LocalScript
s may have access to server-side only services, such as ServerStorage
or ServerScriptService
. There is no separation between the server and client. It all runs on the client.FilteringEnabled
, they're separated even more, and this separation is much more apparent.FilteringEnabled
, and everything is being done by the client. You should handle the cloning to the server. Although technically it would be bad to check the requirements (such as checking if player has enough money) on the client, you don't want to overwhelm the server with all of this checking. Use a RemoteFunction
to get the price of the GravityCoil
, and a RemoteEvent
to handle the cloning.--LocalScript, inside the same place you have it local rep = game:GetService"ReplicatedStorage" local plr = game:GetService("Players").LocalPlayer local price = rep:WaitForChild("GetPrice"):InvokeServer"GravityCoil" local giveTool = rep:WaitForChild"GiveTool" script.Parent.MouseButton1Click:Connect(function() if plr.leaderstats.Money.Value >= price then giveTool:FireServer"GravityCoil" end end)
--Server Script local rep = game:GetService"ReplicatedStorage" local getPrice = rep:WaitForChild"GetPrice" local giveTool = rep:WaitForChild"GiveTool" giveTool.OnServerEvent:Connect(function(player, toolName) rep[toolName]:Clone().Parent = player.Backpack rep[toolName]:Clone().Parent = player.StarterGear --Cloning handled here end) local GetToolPrice GetToolPrice = function(player, toolName) return rep[toolName].Price.Value --I inserted an IntValue inside the tool called Price. end getPrice.OnServerInvoke = GetToolPrice
Lighting
as storage, as this is in no way supported by ROBLOX. Learn more here.