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

How do I get from the player's model to the player?

Asked by
lucas4114 607 Moderation Voter
9 years ago

Problem is in the script.

function inHitbox (p)
    p.Player.PlayerGui.GetInCarGui.TextLabel.Visible = true --Heres the problem, when I do "p.Player" I'm trying to get to the player of the, the player is the "game.Player", it works to get from the player to the model, but using player.character but I wanna get from the model to the player.
     if script.Parent.Hitbox.TouchEnded then
        return(7)
        p.Player.PlayerGui.GetInCarGui.TextLabel.Visible = false
    end
end

script.Parent.Hitbox.Touched:connect(inHitbox)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

There is a function of game.Players called GetPlayerFromCharacter that takes in arguments of the character you're getting the player of.

script.Parent.Hitbox.Touched:connect(function(p)
    --Get the player
    local plr = game.Players:GetPlayerFromCharacter(p)
    --Check if player exists
    if plr then
        plr.PlayerGui.GetInCarGui.TextLabel.Visible = true
        --Wait for the TouchEnded event to fire
        script.Parent.TouchEnded:wait()
        plr.PlayerGui.GetInCarGui.TextLabel.Visible = false
    end
end)
0
It works, and you know all you could have done is simply adding it into my script, but I did it myself then... lucas4114 607 — 9y
0
Your script wouldn't have worked Goulstem 8144 — 9y
Ad

Answer this question