I'm confused on how to fix my shop thingy, so basically when I play the game. I can purchase trails but when I purchase more than one trail the other one doesn't get deleted and it gets quite glitchy, can anyone fix this for me please? (The wantedtrails are remoteevents and don't worry about the leaderstats, I only want the double trail problem fixed) First script:
wantedtrail = nil script.Parent.MouseButton1Click:Connect(function() if game.Players.LocalPlayer.leaderstats.Rebirths.Value >= 1 then wantedtrail = "WhiteTrail" game.Players.LocalPlayer.leaderstats.Rebirths.Value = game.Players.LocalPlayer.leaderstats.Rebirths.Value - 1 workspace.Events.Trail:FireServer(wantedtrail) end end)
Second Script:
wantedtrail = nil script.Parent.MouseButton1Click:Connect(function() if game.Players.LocalPlayer.leaderstats.Rebirths.Value >= 2 then wantedtrail = "RedTrail" game.Players.LocalPlayer.leaderstats.Rebirths.Value = game.Players.LocalPlayer.leaderstats.Rebirths.Value - 2 workspace.Events.Trail:FireServer(wantedtrail) end end)
Excuse my minimal brain activity, it's past midnight and I'm supposed to be sleeping, anyways,
You can prevent this from happening by simply using the script to check if the user's 'backpack' or current equipped tool has/is named the one in the shop that you're selling, if the tool is located inside of the player, the shop prevents another from being bought. While I'm too tired and lazy to write you any code, but I'll give you some examples.
You can use if x:FindFirstChild(y) then to check if the path x has an instance/object named y
The directories/paths you'll need to check for the tool are:
Player.Character
and
Player.Backpack
You can do something like
if Player.Character:FindFirstChild("golden_sword") or Player.Backpack:FirstFirstChild("golden_sword") then print("user already has item") else print("user doesnt have the item!") end