What do you want to achieve? I want the player to be able to buy a sword from a GUI shop and when they have bought it they can’t buy it again and it saves for the next time they join.
What is the issue? When the player buys the sword, they can buy it as many times as they want and they lose their money. And when they leave the sword does not save. Also there’s no error message.
What solutions have you tried so far? The first thing I did was try to end the script if the “bought” value for a sword was true, and if it wasn’t then proceed to the next frame. But I couldn’t Figure out how to do that and I even searched all over the DevForum and the closest thing I came to find related to what I wanted was someone trying to end a function that was in a loop. It let me buy the sword and it took my yen but if I kept buying it, it would keep giving it to me. And once I left it didn’t save so I had to buy it all over again. After that, I tried putting all the scripts into one whole script and that seems like the better solution but it’s actually a lot more complicated. But I want to keep it all in one script so it’d be easier for me to explain what I’m trying to do and what the problems are.
So here’s the GUI script that I’m working with (normal script)
game.Players.PlayerAdded:Connect(function(player) -- Inside Of ( ) Is The Parent local plr = script.Parent.Parent.Parent.Parent local rs = game.ReplicatedStorage local ShopGUI = script.Parent.Parent --ScreenGui local Background = script.Parent --Frame local Buy = script.Parent.BuyButton --TxtButton(Background) local Sword = script.Parent.Sword1 --TextLabel(Background) local Bought = script.Parent.Sword1.Bought --StringValue(sword) local Finish = script.Parent.Parent.CompletePurchase --frame local RuSure = script.Parent.Parent.CompletePurchase.Confirmation --Textbox(Finish) local Yes = script.Parent.Parent.CompletePurchase.Accept --Txtbutton (Finish) local Nevermind = script.Parent.Parent.CompletePurchase.Decline --TxtButton (Finish) Buy.MouseButton1Click:Connect(function() if Bought.Value == false and player.Data.Yen.Value >= 700 then --If The Player Did Not Already buy the sword and they if have enough yen Finish.Visible = true --Confirmation That You Wanna Buy The Sword elseif Bought.Value == true then return --If The Player DID Buy the Sword then End script end if Finish.Visible == true then --Confirmation Yes.MouseButton1Click:Connect(function() -- If Confirmed local newsword = rs.Katana:Clone() -- newsword.Parent = plr.Backpack --Clone and give sword to player player.Data.Yen.Value = player.Data.Yen.Value - 700 --Pay up player.Data.Sword.Value = Sword.Text -- Save Sword Data As Sword's Text In Shop ("Commoner's Sword") Bought.Value = true --Player Bought the sword end) end end) end)
I could Also provide the other scripts and Guis that worked fine but sold the sword more than once and didn’t save the purchase when I left, but I’d have to create a model and send the link because it’s a lot.
I also could provide my datastoring scripts if that’s also needed.
Also just wanted to say that I’m still learning about scripting so sorry if I’m asking for a lot.