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

Why won't my function for my GUI work?

Asked by
tanzane 100
9 years ago
function talk(plr)
    if plr:GetRankInGroup(1056046) >= 7 then
local Msg = Instance.new("Hint", workspace)
        Msg.Text = "One Krabby Patty, please."
Msg:remove()
    end
end

script.Parent.MouseButton1Up:connect(talk)

The script is inside a surface gui on a brick... And the parent of the button is a frame, the final parent is a surface gui. So the scripts parent is the button.

Might of confused you there....

This is a regular script inside a Textbutton. Every time I click the GUI, it says:

attempt to index local 'plr' (a number value)

What's wrong with it?

Help me...

1 answer

Log in to vote
0
Answered by
Mowblow 117
9 years ago

So, I took a look at the SurfaceGUI wiki page. It says that "SurfaceGUIs must be a descendant of PlayerGUI in order to know the player who is interacting with it"

What this means is you must put the SurfaceGUI in the StarterGUI to find what player is interacting with it. SurfaceGUIs cannot find the interacting player on their own. You likely have an instance called a TextButton that runs the script, so this is going upon this inference.

You may be asking "But how will this show up in the workspace then?"

The answer is that you must set the adornee of the SurfaceGUI to the part that you want the SurfaceGUI to appear on. You need a localscript inside the SurfaceGUI that contains your previous code and mine:

For example:

local plr = game.Players.LocalPlayer
Player:WaitForChild(Character)
wait(1)
script.Parent.Adornee = game.Workspace.YourPartName

script.Parent.TextButton.MouseButton1Click:connect(function()
-- Your code inside a function that runs when someone clicks the textbutton
function talk(plr)
if plr:GetRankInGroup(1056046) >= 7 then
local Msg = Instance.new("Hint", workspace)
Msg.Text = "One Krabby Patty, please."
Msg:remove()
end
end
end)

I hope this works, and helps.

0
Oops, sorry I didn't explain my question well enough. The script is inside a surface gui... It's not in the starter gui. Props for a AMAZING explanation though tanzane 100 — 9y
0
Alright, I will also try to write another one. Mowblow 117 — 9y
2
Just edited my new answer. Mowblow 117 — 9y
Ad

Answer this question