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
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!
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)