script.Parent.MouseButton1Click:connect(function()
local RS = game:GetService("ReplicatedStorage")
local item = RS:WaitForChild("SubspaceGun")
local price = 250
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
if stats.Cash.Value == price then
stats.Cash.Value = stats.Cash.Value - price
local cloned = item:Clone()
local cloned2 = item:Clone()
cloned2.Parent = player.Backpack
cloned.Parent = player.StarterGear
end
end)
Why won't the player get a tool when they buy something with in game currency?
1 answer
Just so you know, because this is a local script, when a player buys something their cash wont actually be taken away, it'll be taken away on their client, but on the server they'll still have their Cash. You can use a RemoteEvent to fix this, just insert a RemoteEvent into ReplicatedStorage, and you can name it anything, just make sure if you rename it, rename 'RemoteEvent' to the name you've changed it to inside of the scripts.
Also another thing that I noticed is that you were checking if your Cash was equal to the price. Meaning that you had to have exactly 250 Cash to purchase the Tool, you can fix this with >=, which will check if your cash is either over or equal to the price.
Local Script:
script.Parent.MouseButton1Click:Connect(function()
local rs = game:GetService("ReplicatedStorage")
local item = rs:WaitForChild("SubspaceGun")
local price = 250
game.ReplicatedStorage.RemoteEvent:FireServer(item, price)
end)
Server Script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Item, Price)
local Stats = Player:WaitForChild("leaderstats")
if Stats.Cash.Value >= Price then
Stats.Cash.Value = Stats.Cash.Value - Price
local Cloned = Item:Clone()
local Cloned2 = Item:Clone()
Cloned.Parent = Player.Backpack
Cloned2.Parent = Player.StarterGear
end
end)
I've already tested this and it seems to be working fine for me, if it doesn't work for you for whatever reason, just post a comment and I'll try and help you.
6 comments
Okay so the same error is happening it doesn't give it to me, But do I put the Server script in serverscriptservice?
Yes, try putting the Server Script inside ServerScriptService, that's where I put the script when I tested it.
Okay Idk what to do then
It's still not working for you?
Yes
Then I'm not sure, check in both scripts that you don't have any spelling mistakes.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Does it not appear at all in the Backpack or Starter gear? I don't think that the StarterGear is located in the player, so that's one issue I think your script has.
okay i will check,
StarterGear is located in the player.