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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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!

0
I couldn't find a 'ServerScript'. Can you explain what that is? leilaissmart33 3 — 4y
0
Or, do you mean a module script? leilaissmart33 3 — 4y
0
A ServerScript is named "Script". RaforawesomeAlt 343 — 4y
0
Why isn't the button working? I can't click it. leilaissmart33 3 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)
0
Though i don't see any surface gui, the text label must be in one to be visible ObscureBrandon 0 — 4y
0
I did use a Local Script, and the script was inside the text label. leilaissmart33 3 — 4y

Answer this question