Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Purchasing items in a shop GUI?

Asked by
trecept 367 Moderation Voter
6 years ago

I need help with this shop GUI I'm creating. First, I don't understand how I make a shop GUI for only one player? If it's in the startergui it'll show for everyone when someone buys an item, and in playergui doesn't the gui reset back to whatever is in the startergui when a player dies? And second, how do I check when a player has purchased an item so they can come back to the shop to take the item without paying again? I was thinking of putting a value inside the button to check when it's purchased or not, but exploiters would be able to edit the value and if I put the values in serverstorage how would I make each value for a different player? Sorry, I'm really stuck.

2 answers

Log in to vote
0
Answered by 6 years ago

Okay, so um...

1.You can disable the shop GUI in StarterGui so it won't show for players. If you want it to show for players that want to access the shop, you can make a localscript that enables the GUI when the player does something, like join the game or get near a shop. (RemoteEvents may need to be used for stuff like this)

2.The GUI will automatically reset to its original state if you leave something in the GUI called "ResetOnSpawn" on. If you don't want the GUI to reset when the player resets or dies, simply disable it.

3.If you want to check if a player bought something, you can do something like this :

bought = false

script.Parent.MouseButton1Click:Connect(function() --In a GUI button
    local points = game.Players.LocalPlayer:WaitForChild('leaderstats').Points --Assuming you have a leaderboard with points in it
    if bought == false and points.Value >= 10 then --Checks if bought and has enough points
        points.Value = points.Value - 10
        bought = true
        print('Purchased')
    else
        print("Player already has item!/Doesn't have enough points!")
    end
end)

So basically if the player has enough points, the "bought" value turns true. Now if someone tries to buy it again, it won't let them buy it. You can modify it for your shop.

4.If you want to put values in the ServerStorage for every player, you'd have to make a new value when someone joins. (I really prefer you put it in ReplicatedStorage though as both client and server can access it)

A script that makes the values would be something like this :

game.Players.PlayerAdded:Connect(function(plr) --Player joins
    local value = Instance.new('BoolValue', game.ServerStorage) --Creates boolvalue and puts it in ServerStorage
    value.Name = plr.Name --Sets the value name into the player name
end)

Okay, I think I explained everything you wanted to know. Hope this helped! :D

Ad
Log in to vote
0
Answered by 5 years ago

to make shop gui is easy i made video for it click HERE i made it with easy way and it's working i hope i was helpful

Answer this question