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

attempt to index nil with character?

Asked by 4 years ago

attempt to index nil with character, the script should work this way, u touch it and it anchores your head, it isnt really what i need to do completely

01local part = workspace.ts4
02 
03part.Touched:wait()
04 
05player.Character.Head.Anchored = true
06 
07function onPartTouched()
08    player.Character.Head.Anchored = true
09end
10 
11part.Touched:connect(onPartTouched)

the ''player'' is blue below that i think its nil btw dont take down, i tried

1 answer

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
4 years ago
Edited 4 years ago

player is a variable you have to set. You can get it by using game.Players:GetPlayerFromCharacter(model), which returns nil if the model isn't from a player character. It can be set in localscripts with local player = game.Players.LocalPlayer. BUT you are using a part.Touched event, so you don't need a player unless you want to mess with it too or to rule out npcs. Set a variable for the touched part:

1player.Character.Head.Anchored = true
2 
3function onPartTouched(touch)
4    if touch.Parent:findFirstChild("Humanoid") then --makes sure part is from a humanoid
5        touch.Parent.Head.Anchored = true
6    end
7end
8 
9part.Touched:connect(onPartTouched)
0
thansk IIPedroI -3 — 4y
Ad

Answer this question