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

ServerScriptService.Script:5: attempt to index nil with 'Character' help?

Asked by 5 years ago
Edited 5 years ago

So i have a problem with my script

https://gyazo.com/d01fd3948fa7efdf7eda62a5b2ebe197

at line 5

https://gyazo.com/41e3022b7efa9e3d6872f2361b236ea1

01        local player = game.Players.LocalPlayer
02 
03 
04local plr = game.Players.LocalPlayer
05local Char = player.Character
06local rp = Char:WaitForChild("HumanoidRootPart")
07 
08local Debris = game:GetService("Debris")
09local Character = player.Character or script.Parent
10 
11local Humanoid = Character.Humanoid
12 
13 
14 
15local ReplicatedStorage = game:GetService("ReplicatedStorage")
View all 76 lines...
0
Change local Char = player.Character to local Char = player:WaitForChild("Character") ? Since the character isn't loaded yet when the script is working Nguyenlegiahung 1091 — 5y
0
15:25:40.943 - ServerScriptService.Script:5: attempt to index nil with 'WaitForChild' themaxogamer 58 — 5y
0
Is your script a local script? cause you can't use localplayer on normal script (Also local script doesn't work in ServerScriptService) Nguyenlegiahung 1091 — 5y
0
its script themaxogamer 58 — 5y

2 answers

Log in to vote
1
Answered by
AspectW 431 Moderation Voter
5 years ago
Edited 5 years ago

Why do you have 2 variables for player? Remove one.

1local Char = player.Character or player.CharacterAdded:Wait() --waits for the player if it doesn't find one

It seems your script is a ServerScript (reading the comments), you can not get the LocalPlayer from a ServerScript, only from a LocalScript.

0
i sent the local script in answers you mind checking it out themaxogamer 58 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

heres the local script

01local ReplicatedStorage= game:GetService("ReplicatedStorage")
02local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
03local Sound1 = script.Parent.WaterSound1
04local Sound4 = script.Parent.WaterSound4
05local Sound3 = script.Parent.WaterSound3
06local Debris = game:GetService("Debris")
07 
08 
09local player = game.Players.LocalPlayer
10 
11local char = player.Character
12 
13local rp = char:WaitForChild("HumanoidRootPart")
14 
15 
View all 40 lines...
0
Why do you have 2 definitions of the LocalPlayer? Remove one and it should work. PrismaticFruits 842 — 5y

Answer this question