Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why is my script only working one time when a player buys the item nobody can buy it again?


--local script
local gui = script.Parent
local plr = game.Players.LocalPlayer
local remote = game.ReplicatedStorage.Buy

gui.MouseButton1Click:Connect(function(click)
    if plr.leaderstats.Beli.Value >= 100 then
plr.PlayerGui.Stats.Inv.TextLabel.Text = "Katana"
if plr.PlayerGui.Stats.Inv.TextLabel.Text == "Katana" then
    remote:FireServer()
end
end
end)
---server script
local remote = game.ReplicatedStorage.Buy

remote.OnServerEvent:Connect(function(plr)
    game.Lighting.Change.Parent = plr.Backpack
    plr.leaderstats.Beli.Value = plr.leaderstats.Beli.Value - 100
 plr.Backpack:WaitForChild("Change").Value = plr.Backpack:WaitForChild("Change").Value + 1
end)
why this only working once? i mean if somebody did it and somebody else buys it it doesnt work 

1 answer

✓ Accepted answer

The problem is that you're moving the object in lighting instead of making a new object.

--server script

remote.OnServerEvent:Connect(function(plr)
    local clone = game.Lighting.Change:Clone()
    clone.Parent = plr.Backpack
    plr.leaderstats.Beli.Value = plr.leaderstats.Beli.Value - 100
 plr.Backpack:WaitForChild("Change").Value = plr.Backpack:WaitForChild("Change").Value + 1
end)

You shouldn't be using Lighting to store values by the way. You should consider switching to ServerStorage

This discussion is preserved as it was. New answers, comments, and votes are closed.