local cost = 120 script.Parent.MouseButton1Click:connect(function(localPlayer) if localPlayer.leaderstats.Time.Value >= cost then game.ReplicatedStorage.Sword1:Clone().Parent = localPlayer.Backpack script.Parent.BackgroundColor3 = Color3(0,255,0) wait(2) script.Parent.BackgroundColor3 = Color3(255,255,255) else script.Parent.BackgroundColor3 = Color3(255,0,0) wait(2) script.Parent.BackgroundColor3 = Color3(255,255,255) end end)
First off, use RemoteEvents since the FilteringEnabled update came around to stop exploiters.
When using a RemoteEvent it would be like this, put the Sword in ServerStorage, and make a remote in ReplicatedStorage named "BuySword"
Localscript
local player = game.Players.Localplayer script.Parent.MouseButton1Click:connect(function() game.ReplicatedStorage.BuySword:FireServer() if player.leaderstats.Time.Value >= 120 then script.Parent.BackgroundColor3 = Color3(0,255,0) wait(2) script.Parent.BackgroundColor3 = Color3(255,255,255) else script.Parent.BackgroundColor3 = Color3(255,0,0) wait(2) script.Parent.BackgroundColor3 = Color3(255,255,255) end end)
Serverscript
local cost = 120 game.Players.PlayerAdded:Connect(function(player) local stats = Instance.new("Folder", player) stats.Name = "leaderstats" local Time = Instance.new("NumberValue", stats) Time.Name = "Time" end) game.ReplicatedStorage.BuySword.OnServerEvent:Connect(function(player) if player.leaderstats.Time.Value >= cost then game.Serverstorage.Sword1:Clone().Parent = player.Backpack end end)