Yes all of them I using to buy
Weād need to acknowledge how many times it prints out when a singular event is called. The codeās not the issue, and thereās no need to utilise a check for only one tool. The script should regularly subtract 200 as intended, but if it exceeds the amount, it signifies the RemoteEventās called more than once.
I will try that
new script againā¦:
--local script
local player = game:GetService("Players").LocalPlayer
local remoteEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("BuyItemEvent")
local function buyItem()
local toolName = "Fake Knife"
remoteEvent:FireServer()
script.Parent.Bought.BackgroundColor3 = Color3.fromRGB(0,255,0)
end
script.Parent.MouseButton1Click:Connect(buyItem)
--serverscript
local Tools = game.ReplicatedStorage:WaitForChild("Tools")
local Tool = Tools:FindFirstChild("Fake Knife")
local whatToBuy = "Fake Knife"
game.ReplicatedStorage.Events.BuyItemEvent.OnServerEvent:Connect(function(player,toolName)
if toolName == whatToBuy then
if player.leaderstats.Cash.Value >= 200 then
print(player.Name .. " Bought " .. Tool.Name)
print(player.leaderstats.Cash.Value)
Tool:Clone().Parent = player:FindFirstChild("Backpack")
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 525
end
end
end)
Yeah, could you show the other scripts handling the transaction as well?
What do you mean by that sorry?
Oh yeah ok
--grapple local
local player = game:GetService("Players").LocalPlayer
local remoteEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("BuyItemEvent")
local function buyItem()
local toolName = "Grapple Gun"
remoteEvent:FireServer(toolName)
script.Parent.Bought.BackgroundColor3 = Color3.fromRGB(0,255,0)
end
script.Parent.MouseButton1Click:Connect(buyItem)
--grapple server
local Tools = game.ReplicatedStorage:WaitForChild("Tools")
local Tool = Tools:FindFirstChild("Grapple Gun")
local whatToBuy = "Grapple Gun"
game.ReplicatedStorage.Events.BuyItemEvent.OnServerEvent:Connect(function(player, toolName)
if toolName == whatToBuy then
if player.leaderstats.Cash.Value >= 200 then
print(player.Name .. " Bought " .. Tool.Name)
print(player.leaderstats.Cash.Value)
Tool:Clone().Parent = player:FindFirstChild("Backpack")
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 200
end
end
end)
--laser local
local player = game:GetService("Players").LocalPlayer
local remoteEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("BuyItemEvent")
local function buyItem()
local toolName = "Laser Gun"
remoteEvent:FireServer(toolName)
script.Parent.Bought.BackgroundColor3 = Color3.fromRGB(0,255,0)
end
script.Parent.MouseButton1Click:Connect(buyItem)
--laser server
local Tools = game.ReplicatedStorage:WaitForChild("Tools")
local Tool = Tools:FindFirstChild("Laser Gun")
local whatToBuy = "Laser Gun"
game.ReplicatedStorage.Events.BuyItemEvent.OnServerEvent:Connect(function(player,toolName)
if toolName == whatToBuy then
if player.leaderstats.Cash.Value >= 200 then
print(player.Name .. " Bought " .. Tool.Name)
print(player.leaderstats.Cash.Value)
Tool:Clone().Parent = player:FindFirstChild("Backpack")
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 350
end
end
end)
--knife local
local player = game:GetService("Players").LocalPlayer
local remoteEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("BuyItemEvent")
local function buyItem()
local toolName = "Fake Knife"
remoteEvent:FireServer(toolName)
script.Parent.Bought.BackgroundColor3 = Color3.fromRGB(0,255,0)
end
script.Parent.MouseButton1Click:Connect(buyItem)
--knife server
local Tools = game.ReplicatedStorage:WaitForChild("Tools")
local Tool = Tools:FindFirstChild("Fake Knife")
local whatToBuy = "Fake Knife"
game.ReplicatedStorage.Events.BuyItemEvent.OnServerEvent:Connect(function(player,toolName)
if toolName == whatToBuy then
if player.leaderstats.Cash.Value >= 200 then
print(player.Name .. " Bought " .. Tool.Name)
print(player.leaderstats.Cash.Value)
Tool:Clone().Parent = player:FindFirstChild("Backpack")
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 525
end
end
end)
--My script doesnt work anymore
Dumb question; The buttons are different, right?
⦠No they are all image Buttons lol
Ignore all the >= 200 except for the top one lol mistake
I mean they arenāt the same button right? lol
Oh no no no no no lemme show you:
Okay, I think I found the problem. Put the normal scripts in ServerScriptService. And you donāt need 3 different scripts, thatās where the problemās happening. Just check the types on the server, like so:
local function checkTool(name)
if ToolFolder:FindFirstChild(name) then
return ToolFolder[name]
end
end
Where would I put this in ? for the on server event thing
local Tools = game.ReplicatedStorage:WaitForChild("Tools")
local function checkTool(name)
if Tools:FindFirstChild(name) then
return Tools[name]
end
return nil
end
game.ReplicatedStorage.Events.BuyItemEvent.OnServerEvent:Connect(function(player,toolName)
local Tool = checkTool(toolName)
if not Tool then return end
if player.leaderstats.Cash.Value >= 200 then
print(player.Name .. " Bought " .. Tool.Name)
print(player.leaderstats.Cash.Value)
end
end)
I add my backpack tool in it right?
Script part lol my brain is not working rn lol
It will check if the tool exists and if it does, then itāll process the transaction.