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

TextButton that only works for some players?

Asked by 8 years ago

So I made a SurfaceGui and I want to make it so the TextButton can only be clicked by me. How would I do that?

local part = Instance.new("Part", workspace)
part.Size = Vector3.new(50,50,4)
local screen = Instance.new("SurfaceGui", part)
local frame = Instance.new("Frame", screen)
frame.Size = UDim2.new(1,0,1,0)
frame.Style = "DropShadow"
wait(-.1000)
local button = Instance.new("TextButton", screen)
button.Size = UDim2.new(.5,0,.5,0)
button.Position = UDim2.new(.25,0,.25,0)
button.Style = "RobloxRoundButton"
button.MouseButton1Down:connect(function()
print "Clicked!"
--But how do I make it so only I Can click it and not other players?
end)

Thanks.

1 answer

Log in to vote
0
Answered by 8 years ago
local player = game.Players.LocalPlayer
local part = Instance.new("Part", workspace)
part.Size = Vector3.new(50,50,4)
local screen = Instance.new("SurfaceGui", part)
local frame = Instance.new("Frame", screen)
frame.Size = UDim2.new(1,0,1,0)
frame.Style = "DropShadow"
wait(-.1000)
local button = Instance.new("TextButton", screen)
button.Size = UDim2.new(.5,0,.5,0)
button.Position = UDim2.new(.25,0,.25,0)
button.Style = "RobloxRoundButton"
button.MouseButton1Down:connect(function()
    if player.Name == "silverminer226" then
        print("Clicked")
    end
end)

For this to work, you are gonna need to put the SurfaceGui into StarterGui, so you can get the LocalPlayer

Now you need to Adornee the GUI, so it's parent is then the block it is on. As I do not know what block and where it is, I can not set the Adornee, but the wiki will show you how to do it.

  • NinjoOnline
0
I get this error "20:58:39.643 - LocalScript is not a valid member of Players" Did you mean LocalPlayer? silverminer226 4 — 8y
0
Oh yeah, oops, yeah it is LocalPlayer NinjoOnline 1146 — 8y
Ad

Answer this question