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

How do you make a script that you click a button, then your user is on the part?

I've been trying to make a script where you click a button, then the user's username is on the text label. I tried this:

local player = game.Players.LocalPlayer

local Claimer = workspace.Claimer

local ClaimButton = workspace.Claimer.TextLabel

if Claimer.Clicked then ClaimButton.Text = player.Name end

2 answers

TextLabels don't have clicked events. You're looking for TextButtons. TextButtons have a Mouse1ButtonDown event, which you could connect to by doing this:

TextButton.Mouse1ButtonDown:Connect(function()
	game.ReplicatedStorage.ClaimRemote:FireServer(TextButton)
end)

This would need to be in a LocalScript in StarterPlayerScripts.

You also need to set up a remote in ReplicatedStorage called ClaimRemote. Then, a ServerScript in ServerScriptService. Here, you would add something like:

game.ReplicatedStorage.ClaimRemote.OnServerEvent:Connect(function(plr, button)
	button.Text = plr.Name
end)

This is a start, you also need to check to make sure people can't claim other people's land, and so on

Reply with further questions,

and please mark as correct if this solution works for you!

4 comments

0

I couldn't find a 'ServerScript'. Can you explain what that is?

0

Or, do you mean a module script?

0

A ServerScript is named "Script".

0

Why isn't the button working? I can't click it.

make sure its a local script because you LocalPlayer is nil on the server. Unless you want the username shown to everyone. if so,

local Claimer = workspace.Claimer;
local ClaimLabel = workspace.Claimer.TextLabel;

Claimer.MouseClick:Connect(function(clicker)
	ClaimLabel.Text = clicker.Name;
end)

2 comments

0

Though i don't see any surface gui, the text label must be in one to be visible

0

I did use a Local Script, and the script was inside the text label.

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