Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Have Weapon Shop, Currency Won't Subtract?

I am making a weapon shop, and I have a successful script so that if you have the money for something on the GUI you can buy it. What I can't figure out is how to subtract the cost of that weapon from the player's amount. here's the script:

local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
if plr.leaderstats.Cash.Value >= 500 then
replicatedstorage.MachineGun:Clone().Parent = plr.Backpack
	replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear
	if script.Parent.MouseButton1Click and plr.leaderstats.Cash.Value >= 500 then
		game.plr.leaderstats.Cash.Value = game.plr.leaderstats.Cash.Value - 500
	end
end


end)

Can you please tell me what's wrong, thank you very much!

2 comments

0

I think it was you who gave an anwer that was wrong, I was able to fix it and even though the script wasn't completely right I want to give you credit, repost it so that I can accept your answer!

3 answers

✓ Accepted answer

https://www.roblox.com/library/184275443/UltraWorks-Shop-Creator-Pro-tools

Use that plugin it is a great way to make weapon shops buddy :]

Also for your question try doing this script

local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
if script.Parent.MouseButton1Click and plr.leaderstats.Cash.Value >= 500 then
replicatedstorage.MachineGun:Clone().Parent = plr.Backpack
    replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear
        game.plr.leaderstats.Cash.Value = game.plr.leaderstats.Cash.Value - 500
    end
end


end)

Good luck in your game! :D

3 comments

0

ur so kind dude

0

np, and btw your only mistake was this at the top I set a variable for plr that was game.Players.LocalPlayer, so the games you inserted weren't needed, and also the end you put in was needed either, but besides that, thanks, it was a simple mistake! Plue your the only person who didn't try to change my whole script around!

0

i didnt try to change the whole script arund cause i cant even script XP

Check ifyou have FilteringEnabled turned on. If it is turned on then make a RemoteEvent in ReplicatedStorage Change your scripts to this:

local plr = game.Players.LocalPlayer

local replicatedstorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
	if plr.leaderstats.Cash.Value >= 500 then
		replicatedstorage.MachineGun:Clone().Parent = plr.Backpack
    		replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear
        	game.ReplicatedStorage.RemoteEvent:FireServer(500) 
	end
end)

insert a script into ServerScriptService and enter the following script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player , amount)
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 500
end)

You've already indicated if someone MouseButton1Clicks and if their money value is 500 or over so instead it would be:

local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
if plr.leaderstats.Cash.Value >= 500 then
replicatedstorage.MachineGun:Clone().Parent = plr.Backpack
    replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear
    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value
end
end)

Also in the script that you made:

local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
if plr.leaderstats.Cash.Value >= 500 then
replicatedstorage.MachineGun:Clone().Parent = plr.Backpack
    replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear
    if script.Parent.MouseButton1Click and plr.leaderstats.Cash.Value >= 500 then
        game.plr.leaderstats.Cash.Value = ERROR IS HERE : game.plr.leaderstats.Cash.Value - 500
    end
end
end)

Where it says "ERROR IS HERE", basically, the error is that you've already made a variable called plr, so there's no point is saying 'game.plr.leaderstats.Cash.Value - 500' when instead you can just say 'plr.leaderstats.Cash.Value - 500'

I hope this answered your question!

This discussion is preserved as it was. New answers, comments, and votes are closed.