Serverside: (ServerScriptService)
function onPurchase(player,item)
local price = 0
if item == "RainbowTrail" then
price = 30
elseif item == "BlueTrail" then
price = 30
elseif item == "PinkTrail" then
price = 30
elseif item == "GreenBlueTrail" then
price = 30
elseif item == "LimeTrail" then
price = 30
elseif item == "PinkBlueTrail" then
price = 30
elseif item == "PewdiepieTrail" then
price = 399
elseif item == "LennyFace" then
price = 100
end
if player.XP.Value >= price then
player.XP.Value = player.XP.Value - price
local pstats = game.ServerStorage.Stats:FindFirstChild(player.Name)
local val = pstats:FindFirstChild(item)
val.Value = true
return true
else
return false
end
end
local function checktrail(player)
for _, child in pairs(player.Character.Head:GetChildren()) do
if child ~= nil then
if child:IsA("Trail") then
child:Destroy()
player.Character.Head.Attachment0:Destroy()
player.Character.HumanoidRootPart.Attachment1:Destroy()
end
end
end
for _, child in pairs(player.Character.HumanoidRootPart:GetChildren()) do
if child ~= nil then
if child:IsA("ParticleEmitter") then
child:Destroy()
end
end
end
end
function equipItem(player,item)
local pstats = game.ServerStorage.Stats:FindFirstChild(player.Name)
if pstats then
local val = pstats:FindFirstChild(item)
if val.Value == true then
local head = player.Character.Head:GetChildren()
local trail = game.ServerStorage.Items:FindFirstChild(item)
checktrail(player)
local newtrail = trail:Clone()
if newtrail:IsA("Trail") then
local A0 = Instance.new("Attachment",player.Character.Head)
local A1 = Instance.new("Attachment",player.Character.HumanoidRootPart)
A0.Name = "Attachment0"
A1.Name = "Attachment1"
A1.Position = Vector3.new(0, -0.8, 0)
newtrail.Attachment0 = A0
newtrail.Attachment1 = A1
newtrail.Parent = player.Character.Head
else if newtrail:IsA("ParticleEmitter") then
newtrail.Parent = player.Character.HumanoidRootPart
end
return true
end
end
end
end
function returnValue(player,item)
local stats = game.ServerStorage.Stats
if stats:FindFirstChild(player.Name) then
local pstats = stats:FindFirstChild(player.Name)
if pstats:FindFirstChild(item) then
return pstats:FindFirstChild(item).Value
end
end
end
game.ReplicatedStorage.OnPurchase.OnServerInvoke = onPurchase
game.ReplicatedStorage.ReturnValue.OnServerInvoke = returnValue
game.ReplicatedStorage.OnEquip.OnServerInvoke = equipItem
game.ReplicatedStorage:FindFirstChild("Remove").OnServerEvent:Connect(checktrail)
PurchaseHandler (Localscript inside the shop UI)
local trails = script.Parent.MainFrame:GetChildren()
local indexbutton = nil
local erro = game.Workspace.Music.errorsound
en = true
for i = 1, #trails do
if trails[i]:IsA("Frame") and trails[i]:WaitForChild("TextButton") then
local button = trails[i]:FindFirstChild("TextButton")
button.MouseButton1Down:connect(function()
if en == true then
en = false
local val = game.ReplicatedStorage.ReturnValue:InvokeServer(trails[i].Name)
if val == false then
local purchase = game.ReplicatedStorage.OnPurchase:InvokeServer(trails[i].Name)
if purchase == true then
script.Sound:Play()
-- If purchase is true then the item has been bought successfuly, equip is now enabled
button.Text = "EQUIP"
button.TextColor3 = Color3.fromRGB(172, 172, 172)
--
button.BackgroundColor3 = Color3.fromRGB(165, 165, 165)
else
button.Text = "NO $$$$"
button.BackgroundColor3 = Color3.fromRGB(255, 43, 46)
button.Parent.BackgroundColor3 = Color3.fromRGB(255, 43, 46)
erro:Play()
wait(0.5)
button.Text = "PURCHASE"
button.BackgroundColor3 = Color3.fromRGB(255,255,255)
button.Parent.BackgroundColor3 = Color3.fromRGB(255,255,255)
end
elseif val == true then
local equip = game.ReplicatedStorage.OnEquip:InvokeServer(trails[i].Name)
if equip == true then
button.Text = "EQUIPPED"
button.TextColor3 = Color3.fromRGB(112, 112, 112)
button.BackgroundColor3 = Color3.fromRGB(106, 106, 106)
if indexbutton ~= nil then
indexbutton.Text = "EQUIP"
indexbutton.TextColor3 = Color3.fromRGB(172, 172, 172)
--
button.BackgroundColor3 = Color3.fromRGB(165, 165, 165)
end
indexbutton = button
end
end
wait(0.5)
en = true
end
end)
end
end
game.ReplicatedStorage.OnRespawn.OnClientEvent:connect(function()
for i = 1, #trails do
if trails[i]:WaitForChild("TextButton") then
local button = trails[i]:FindFirstChild("TextButton")
local val = game.ReplicatedStorage.ReturnValue:InvokeServer(trails[i].Name)
if val == true then
button.Text = "EQUIP"
button.TextColor3 = Color3.fromRGB(172, 172, 172)
--
button.BackgroundColor3 = Color3.fromRGB(165, 165, 165)
end
end
end
end)
![image](//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/4X/6/4/8/648f569326296e9f05e526c74bea9b084aec1a49.png)