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

How would I go about making a surface gui script? The current script I have won't work.

Asked by
54013 -2
5 years ago
Edited 5 years ago

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.

0
What is a NormalScript? User#19524 175 — 5y
0
A normal script as in just a script compared to a localscript. 54013 -2 — 5y
0
And why is a LocalScript abnormal? User#19524 175 — 5y
0
NormalScript = ServerScript NiniBlackJackQc 1562 — 5y
View all comments (2 more)
0
If it bothered you so much then there, I changed it. 54013 -2 — 5y
0
Is it for a FE game? NiniBlackJackQc 1562 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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 :(

Ad

Answer this question