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

Help with hint?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

How do I get the player name?

part = script.Parent
Player = game.Players.LocalPlayer.humanoid --Get name here
part.Touched:connect(function(hit)

    hit.Transparency = 1
    local hint = Instance.new("Hint", game.Workspace)
    hint.Text = Player.."Has touched  me!"
    wait(1)
    hint:remove()


end)

3 answers

Log in to vote
1
Answered by 8 years ago

In a server script you cant even get the player by using >game.Player.LocalPlayer >. you can see it by 'LocalPlayer', its local.

You can also add debounce for not creating like 1000000 of hints like here:

local part = script.Parent
local debounce = false

if debounce then
    return
end
debounce = true
part.Touched:connect(function()
    --your code not spammed
    print("Not spammed")
end)
debounce = false

if you want to know more on debounce, you can go one roblox wiki here

For beign sure its a player touching the part you can add this little code like that:

if hit.Parent:FindFirstChild("Humanoid") then
    --body
end

here's the you're code:

part = script.Parent

local debounce = false

part.Touched:connect(function(hit)
    if debounce then return end
    debounce = true
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Transparency = 1

        local name = hit.Parent.Name
        local hint = Instance.new("Hint", workspace)
        hint.Text = name.." Has touched  me!"
        wait(1)
        hint:remove()
    end
    debounce = false

end)

Ad
Log in to vote
0
Answered by 8 years ago

Firstly, There is no humanoid property of Player. Instead, to get the player's humanoid, use Player.Character.Humanoid.

Secondly, staying true to the original question, the name of the player is Player.Name.

Lastly, I should mention that Hint, however simple and loved they may be, are deprecated. You should look into GUIs instead. Of course, that's only for really serious development. For small projects, it's fine.

0
Write the script for me, please. I am not sure how to rewrite it. FiredDusk 1466 — 8y
Log in to vote
0
Answered by
iSvenDerp 233 Moderation Voter
8 years ago

Hi... You are calling your player variable wrong...from a server script its Player.Character not Player.LocalPlayer. Also When you do the text it has to be Player.Name. Here is the script.

part = script.Parent
Player = game.Players.Character.Humanoid --Get name here
part.Touched:connect(function(hit)

    hit.Transparency = 1
    local hint = Instance.new("Hint", game.Workspace)
    hint.Text = Player.Name.."Has touched  me!"
    wait(1)
    hint:remove()


end)

I cant test this right now but it should work hope this helped.

0
Did not work FiredDusk 1466 — 8y
0
You're calling tour player variable wring too. XToonLinkX123 580 — 8y
0
your* :L XToonLinkX123 580 — 8y

Answer this question