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

How can I fix this problem? (PLAYER CONNECTING)

Okay, so this part of the script was designed to work when a player steps on a part.

The problem I'm having (I think, anyways) is connecting the player to the brick when he/she touches it.

function onTouched(part)

local humanoid = part.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then

local a = Instance.new('Message', workspace)
	player.Character.Torso.Anchored = true
		a.Text = "Tutorial Loading."
	wait(.5)
		a.Text = "Tutorial Loading.."
	wait(.5)
		a.Text = "Tutorial Loading..."

local clon = game.Lighting.Sofa:Clone()
	clon.Parent = game.Workspace
	clon:MoveTo(Vector3.new(3.301, 0.7, 36.088)) --Models don't have position. To move a model use :MoveTo(Vector3.new())
	wait(.2)
player.Character.Torso.Anchored = false
				end
			end
print '4'

1 answer

As Script analysis will be telling you, you haven't defined player anywhere.


The only object you have access to is part. We have to figure out the player from that.

In particular, part (if it is indeed a player) will be one of the player's character's legs or arms. That means part.Parent would be their character:

	local character = part.Parent

Using the :GetPlayerFromCharacter method of the Players service, we can get the corresponding player:

	local player = game.Players:GetPlayerFromCharacter( character )
	if player then
		-- It is in fact a player
		character.Torso.Anchored = true
		local a = Instance.new("Message", workspace)
		a.Text = "Tutorial loading..."
		wait(3)
		local clon = .....

1 comment

0

Oh, I had player defined in an earlier part of the script, I just left it out since this was the area needed to be fixed. Sorry for not clearing that up beforehand.

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