It isn't giving me the item when I buy it on the roblox server, but in roblox studio, it is giving me the item. Here's the script:
local p = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if p.Backpack:FindFirstChild("GravityCoil") or p.StarterGear:FindFirstChild("GravityCoil") or game.Workspace[p.Name]:FindFirstChild("Backpack") then script.Parent.Parent.YoruPrice.Text = "You already brought this item!" wait(5) script.Parent.Parent.YoruPrice.Text = " Gravity Coil - 1,000" else if p.leaderstats.Cash.Value >= 1000 then replicatedstorage.Yoru:Clone().Parent = p.Backpack replicatedstorage.Yoru:Clone().Parent = p.StarterGear p.leaderstats.Cash.Value = p.leaderstats.Cash.Value - 1000 else local cashrequirement = 1000 - p.leaderstats.Cash.Value script.Parent.Parent.YoruPrice.Text = "You need " ..cashrequirement.. " more money to buy this item!" wait(5) script.Parent.Parent.YoruPrice.Text = " Yoru - 1,000" end end end)
I redid the entire script. To make it more sleek and cleaner. Anyways here it is also a image on how i set it up in studio
-- Variables local player = script.Parent.Parent.Parent.Parent local character = game.Workspace:WaitForChild(player.Name) local replicatedstorage = game:GetService("ReplicatedStorage") local missingcash = 0 local price = 1000 -- Functions script.Parent.MouseButton1Click:connect(function() -- Check if player already owns item if player.Backpack:FindFirstChild("GravityCoil") or character:FindFirstChild("GravityCoil") or player.StarterGear:findFirstChild("GravityCoil") then script.Parent.Text = "You already own this item!" wait(5) script.Parent.Text = " Gravity Coil - 1,000" else if player.leaderstats.Cash.Value >= price then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price local gear = replicatedstorage.GravityCoil:Clone() gear.Parent = player.Backpack local startergear = replicatedstorage.GravityCoil:Clone() startergear.Parent = player.StarterGear else missingcash = price - player.leaderstats.Cash.Value script.Parent.Text = "You need " ..missingcash.. " more money to buy this item!" wait(5) script.Parent.Text = "Price | ".. price end end end)
I just fixed it myself, the problem is, I didn't use for loops.