So I am trying to make a surface gui that gives you a weapon when you press the button for the weapon. However the current script I have won't work. The current script I use is one set up for a screen GUI, but how would I change it to work for a surface gui?
cost = 0 local player = game.Players.LocalPlayer script.Parent.MouseButton1Down:connect(function() if player.leaderstats.KOs.Value >= cost then game.ReplicatedStorage.DC15S:FindFirstChild("DC15S"):clone().Parent = player.Backpack else script.Parent.Text = "Can't afford" wait(1) script.Parent.Text = "DC-15S" end end)
This is in a localscript. And yes, I already tried it in a script.
What you are looking for is Adornee and RemoteEvent.
SurfaceGuis have Adornee property where you can change to see your GUI wherever you want to see, but in the meanwhile SurfaceGui will stay in Player's PlayerGui. Cool, right?
So, you still will use LocalScript but also a RemoteEvent and a Script too.
Keep SurfaceGui in PlayerGui(StarterGui if you are going to give the Gui at the start) and keep LocalScript in SurfaceGui. Set SurfaceGui's Adornee to a part you want to view the Gui on.
SurfaceGui.Adornee = game.Workspace.ViewGUIOnThis
Then when purchase is fine and is done, fire a remoteevent. Receive remoteevent event from Script, and then give the player that thing.
LocalScript:
game.ReplicatedStorage.DC15SGiver:FireServer()
ServerScript(Script):
game.ReplicatedStorage.DC15SGiver.OnServerEvent:Connect(function(Player) game.ReplicatedStorage.DC15S:FindFirstChild("DC15S"):Clone().Parent = Player.Backpack end)
Note: This game could be exploitable by high level exploits which I won't give the name here. Please make it as secure as you can.
Please upvote AND accept as answer if this helped! I need upvotes :(