DO not send data like that, it’s really dangerous and could be easily abused by exploiters. Have your data about items on server and check it on server as well
ex:
--server
Items = {
Sword = {Price = 666, Inst = ServerStorage.Sword}
}
Event.OnServerEvent:Connect(function(Player,Item)
local WantedItem = Items[Item]
assert(not WantedItem,"Player must be exploiter or error in code")
if WantedItem then
local leaderstats = Player:FindFirstChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
if coins.Value >= WantedItem.Price then
local Sword = WantedItem.Inst:Clone()
Sword.Parent = Player.Backpack
end
end
end)
--client
local BuyButton = script.Parent
local ShopEvent
BuyButton.MouseButton1Down:Connect(function()
ShopEvent:FireServer("Sword")
end)
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local price = 100
local sword = game.ReplicatedStorage.Swords.BetterSword:Clone()
game.ReplicatedStorage.Buy:FireServer(player, price, sword)
end)
also, when you fire server, do not send Player argument. Because when you :FireServer() the first argument .OnServerEvent will be Player instance that fired the event
thats might be the problem, and as i said before read my edited comment, it would help.
Now it just prints “player must be exploiter or error in code”
server
local Rep = game.ReplicatedStorage.Swords
Items = {
Sword = {Price = 100, Inst = Rep.BetterSword}
}
game.ReplicatedStorage.BuyBetter.OnServerEvent:Connect(function(Player,Item)
local WantedItem = Items[Item]
assert(not WantedItem,"Player must be exploiter or error in code")
if WantedItem then
local leaderstats = Player:FindFirstChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
if coins.Value >= WantedItem.Price then
local Sword = WantedItem.Inst:Clone()
Sword.Parent = Player.Backpack
end
end
end)
Local:
local BuyButton = script.Parent
local ShopEvent = game.ReplicatedStorage.BuyBetter
BuyButton.MouseButton1Down:Connect(function()
ShopEvent:FireServer("Sword")
end)
Deleting assert isn’t necessary, assert fires whenever it receives a falsy value. Just remove the not from it.
Also the if statement is redundant because of the assert so it can be removed.