local event = game.ReplicatedStorage.HatPurchased
event.OnServerEvent:Connect(function(plr,hat,price)
local vibez = plr.leaderstats:FindFirstChild("Vibez")
if vibez then
if vibez.Value >= price then
plr.CharacterAdded:Connect(function(char)
local hatobj = game.ServerStorage.Hats[hat]:Clone()
char.Humanoid:AddAccessory(hatobj)
end)
vibez.Value = vibez.Value - price
end
end
end)
My server script ^
script.Parent.MouseButton1Click:Connect(function(plr)
local remote = game.ReplicatedStorage.HatPurchased
remote:FireServer("FrozenFireHorns",10)
end)
The local script in the button that I pressed ^^
For some reason it deducts the currency, but never ends up adding them to my avatar? Did I do something wrong?
The reason it doesn’t add it is because it’ll only add it once the character respawns, you have to put the code for it outside as well so it will also work the first time it is bought
local event = game.ReplicatedStorage.HatPurchased
event.OnServerEvent:Connect(function(plr,hat,price)
local vibez = plr.leaderstats:FindFirstChild("Vibez")
if vibez then
if vibez.Value >= price then
local hatobj = game.ServerStorage.Hats[hat]:Clone()
plr.Character.Humanoid:AddAccessory(hatobj)
plr.CharacterAdded:Connect(function(char)
local hatobj = game.ServerStorage.Hats[hat]:Clone()
char.Humanoid:AddAccessory(hatobj)
end)
vibez.Value = vibez.Value - price
end
end
end)
This should hopefully work as it’ll add the hat first time and then when the character respawns
Yes but you need an attachment in the handle that has the same name of an attachment on the character so name it HatAttachment if you want it on the hat
Also not sure if you’re aware, but you shouldn’t be getting the price from the client’s arguments. An exploiter could easily buy any hat and just say the price is 0.
It’s probably better to have a shared ModuleScript in ReplicatedStorage where both the client and server can check the price.