I need help with my script because what I’m trying to do is every time you kill someone you’ll get money and with the money you earn you can spend it in the shop and whatever you spend in the shop it will always save in your inventory.
Problem - It wont give you money when you kill someone and when you buy something from the store in puts you in the negatives and when you die it goes away and you hafto buy it all over again every time.
( ive tried looking it up and i keep getting no results or i cant find what i need )
ShopScript:
local rocketBtn = script.Parent.RocketBtn
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("EquipRe")
local item = "RocketLauncher"
local price = 50
local player = game:GetService("Players").LocalPlayer
local function selectRocket()
rocketBtn.BackgroundColor3 = Color3.new(.5, .5, 1)
item = "RocketLauncher"
price = 50
end
local function buyIt()
re:FireServer(item, price)
script.Parent.Visible = false
rocketBtn.BackgroundColor3 = Color3.new(1, 1, 1)
end
buyBtn.Activated:Connect(buyIt)
rocketBtn.Activated:Connect(selectRocket)
local re = rs:WaitForChild("EquipRe")
local function giveTool(player, item, price)
local tool = rs:WaitForChild(item):Clone()
local money = player.leaderstats.Money
money.Value = money.Value - price
tool.Parent = player.Backpack
end
re.OnServerEvent:Connect(giveTool)
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("EquipRe")
local item = "RocketLauncher"
local price = 50
local player = game:GetService("Players").LocalPlayer
local function selectRocket()
rocketBtn.BackgroundColor3 = Color3.new(.5, .5, 1)
item = "RocketLauncher"
price = 50
end
local function buyIt()
re:FireServer(item, price)
script.Parent.Visible = false
rocketBtn.BackgroundColor3 = Color3.new(1, 1, 1)
end
buyBtn.Activated:Connect(buyIt)
rocketBtn.Activated:Connect(selectRocket)```
local re = rs:WaitForChild("EquipRe")
local function giveTool(player, item, price)
local tool = rs:WaitForChild(item):Clone()
local money = player.leaderstats.Money
money.Value = money.Value - price
tool.Parent = player.Backpack
end
re.OnServerEvent:Connect(giveTool)
If you can also show us the Money Kill Script, that would be great. And based on what I see, these are just my assumptions. For starts as to why your money goes into negative, you should check if the player has enough money to purchase the item first. Like this:
if money.Value >= price then
#Stuff
end
Furthermore, another thing I kind of noticed, is that you are getting the price from the Client. Which can easily be altered and abused. The price should always be deducted and decided on the server. And for why you lose your item when you die?
Items in the backpack, besides items in the starterpack, will always be removed. You’ll have to constantly give it back to them with a script. Maybe keep the items they purchased in a table, and cycle through that table with a loop everytime their character is added.
#Side note
It has been a while since I have done anything on Roblox, so I may be wrong in some of my assumptions.
Check if the player’s money is above the price, then give the player a tool
You can also put the tool in StarterGear to prevent player’s from losing it on death
local re = rs:WaitForChild("EquipRe")
local function giveTool(player, item, price)
local tool = rs:WaitForChild(item):Clone()
local tool1 = rs:WaitForChild(item):Clone()
local money = player.leaderstats.Money
if money.Value >= price then
money.Value = money.Value - price
tool.Parent = player.StarterGear
tool1.Parent = player.Backpack
end
end
re.OnServerEvent:Connect(giveTool)
local re = rs:WaitForChild("EquipRe")
local function giveTool(player, item, price) -- Make a function
local tool = rs:WaitForChild(item):Clone() -- Starter gear tool
local tool1 = rs:WaitForChild(item):Clone() -- Backpack tool
local money = player.leaderstats.Money
if money.Value >= price then -- If the money is greater or equal to the price then run other code
money.Value -= price -- Removing the player's money.
tool.Parent = player.StarterGear -- Give the player startergear tool so if they die they get it back
tool1.Parent = player.Backpack -- Then put the tool in backpack so player doesn't need to reset to get it
end
end
re.OnServerEvent:Connect(giveTool)