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

How can I fix this problem? (PLAYER CONNECTING)

Asked by 9 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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 = .....
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. SmokeyIsSmoking 0 — 9y
Ad

Answer this question