Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

It works, and you know all you could have done is simply adding it into my script, but I did it myself then...

0

Your script wouldn't have worked

This discussion is preserved as it was. New answers, comments, and votes are closed.