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

Function and player problems?

Asked by
traigla 75
9 years ago

This is only a snippet, but I'm getting an error on line 4. Worked before, but I replaced the model with a newer version and it broke.

function onTouched(Brick)   
    if enabled == true then
        local Player = Brick.Parent:findFirstChild("Humanoid")
        local Character = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent)

2 answers

Log in to vote
2
Answered by 9 years ago

Well, first, your variables are kind of weird. You name the Humanoid variable 'Player', and the Player variable 'Character'. Anyways, you should try this:

function whenTouched(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then --If it's a player
        local character = hit.Parent
        local humanoid = character:FindFirstChild("Humanoid")
        local player =  game.Players:GetPlayerFromCharacter(character) 
     end
end)

This way you make sure it's an actual player before defining variables.

Ad
Log in to vote
0
Answered by 9 years ago

"f" seems to be lowercase on line 3. Brick.Parent:FindFirstChild("Humanoid")

1
This is a style mistake but not an error. BlueTaslem 18071 — 9y

Answer this question