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

Getting player name and putting it into TextBox?

Asked by 6 years ago

I have a part in Workspace named Part and inside it is a script, I want that script to on touched get the player's name that has just touched the part and put their name in a GUI

local playername = game.StarterGui.checkinGui.mainFrame.playerName
local plrname = game.Players.LocalPlayer

function onTouch()
    playername = plrname.Name
end

script.Parent.Touched:connect(onTouch)

Using a normal Script btw, not a LocalScript.

0
Well what do I put then? ShiforRBLX 5 — 6y
0
Wiki Description: "This property is client-side only! You should use a LocalScript instead of a Script when using it." TheeDeathCaster 2368 — 6y
0
I would use a local script to do this, and then fire a server event the changes the name, and then it already has the value of player in the server script. WorkAtChickenPlace 19 — 6y

3 answers

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
6 years ago

The way to do this via ServerScript would be :GetPlayerFromCharacter() which does exactly what you would think it does, gets the player from a character.

--in a ServerScript
script.Parent.Touched:connect(function(part)
    local maybePlayer = game.Players:GetPlayerFromCharacter(part.Parent)
    if maybePlayer then --if it's a player
        local name = maybePlayer.Name
        --other stuff here
    end
end)
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Not 100% sure this will work and may require some tweaking to your situation, but this is what I got.

--Here is the local script running ON YOUR PERSON
    local Event = repStorage:WaitForChild("YourRemoteEvent")
    part.Touched:connect(function(hit)

if hit.Parent == game.Players.LocalPlayer then
Event:FireServer(hit.Parent)
end



    end)


--Here is the server script
local Event = repStorage:WaitForChild("YourRemoteEvent")
Event.OnServerEvent:connect(function(player, hit)


NavigateToWhereTheTextIs.Text = hit


end)

Like I said, you need to tweak it a little bit, but I think it SHOULD work. I didn't test it so if it doesn't try your best to figure it out, or just reply asking.

0
Um, you say if hit == LocalPlayer, do you mean LocalPlayer.Character? Also, I believe `hit` would be a part of the players character. And one last thing, you set .Text equal to a basePart (which is what hit should be) theCJarmy7 1293 — 6y
0
I fixed it, thanks theCJarmy7 WorkAtChickenPlace 19 — 6y
Log in to vote
0
Answered by 6 years ago

Try This:

--Thanks jamiethegreatQ777 For Making This :)
Credit To jamiethegreatQ777 = true
if Credit To jamiethegreatQ777 == false then return end
game.Workspace.part.SurfaceGui.TextBox.Text = game.players.Localplayer "..PlayerName.."

I'm Sure This Will Work If Not Please Message Me twitter.com/jamiethegreatQ7

Answer this question