Hi! I’m currently trying to make a shop for my game, but unfortunately I have everything finished but one thing, that is when you buy something you don’t receive it. You’d get coins in which you could then redeem them for gears. Every time I test it out on Studio, I always get the message: “ServerScriptService.BuyScript:5:attempt to compare number and Instance”. Here’s the scripts I’ll provide for this issue.
Script #1: BuyScript (troubling script)
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')
local function buyTool(player, tool)
if player.leaderstats.Coins >= tool.Price.Value then
player.leaderstats.Coins = tool.Price.Value
local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
giveTool.Parent = player.Backpack
local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
giveTool.Parent = player.StarterGear
end
end
remoteEvent.OnServerEvent:Connect(buyTool)
Script #2: LeaderboardScript
game.Players.PlayerAdded:Connect(function(plr)
local f = Instance.new("Folder", plr)
f.Name = "leaderstats"
local coins = Instance.new("IntValue", f)
coins.Name = "Coins"
coins.Value = 0
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
coins.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
end)
Script #3: GetCash (Coins)
waittime = 30 -- Time Between each hit
amnt = 10 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Coins")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent.Transparency = 1
script.Disabled = true
wait(waittime)
script.Parent.Transparency = 0
script.Disabled = false
end
end
script.Parent.Touched:connect(onTouched)