Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TextButton that only works for some players?

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

✓ Accepted answer
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

2 comments

0

I get this error "20:58:39.643 - LocalScript is not a valid member of Players" Did you mean LocalPlayer?

0

Oh yeah, oops, yeah it is LocalPlayer

This discussion is preserved as it was. New answers, comments, and votes are closed.