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

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

So i have a problem with my script

https://gyazo.com/d01fd3948fa7efdf7eda62a5b2ebe197

at line 5

https://gyazo.com/41e3022b7efa9e3d6872f2361b236ea1

		local player = game.Players.LocalPlayer


local plr = game.Players.LocalPlayer
local Char = player.Character
local rp = Char:WaitForChild("HumanoidRootPart")

local Debris = game:GetService("Debris")
local Character = player.Character or script.Parent

local Humanoid = Character.Humanoid



local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
TweenService = game:GetService("TweenService")
 
local function RemoveEffect(Ep,Tbr,Len,GSize,GCFrame,GTrans)
    spawn(function()
        wait(Tbr)
        TweenService:Create(Ep,TweenInfo.new(Len,Enum.EasingStyle.Linear),{Transparency = GTrans,Size = GSize,CFrame = GCFrame}):Play()
        Debris:AddItem(Ep,Len+0.5)
end)
end
 
RemoteEvent.OnServerEvent:Connect(function(player, AnimationID, Sound1, Sound4, 					Sound3)
        local Animation = Instance.new("Animation")
        Animation.AnimationId = AnimationID
        local LoadAnimation = Humanoid:LoadAnimation(Animation)
        LoadAnimation:play()
   local Tool = script.Parent
    local Blade = Tool:WaitForChild("Blade")
    local Trail = Blade:WaitForChild("Trail")
    Trail.Enabled = true

    local Character = player.Character or player.CharacterAdded:Wait()
    local RootPart = Character.HumanoidRootPart
    plr.Character.Humanoid.WalkSpeed = 0
    local BV = Instance.new("BodyVelocity")
    BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    BV.Velocity = RootPart.CFrame.lookVector.Unit * 65 --
 
    Sound1:Play()
Sound4:Play()
    spawn(function()
            local WW = ReplicatedStorage:WaitForChild("WaterWheel"):Clone()
            WW.Size = Vector3.new(10.1,10.1,5.1)
       WW.Transparency = 0
            WW.Anchored = true
            WW.CanCollide = false
                wait(0.77)
            WW.CFrame = rp.CFrame * CFrame.Angles(5,1.5,0)
            WW.Parent = workspace
            TweenService:Create(WW,TweenInfo.new(0.25,Enum.EasingStyle.Linear),{Size = Vector3.new(23.44, 26.943, 1.834),Transparency = 0.5,CFrame = rp.CFrame *    CFrame.Angles(10,1.5,0)}):Play()
            RemoveEffect(WW,0.3,0.25,Vector3.new(0.1,0.1,0.1),rp.CFrame *   CFrame.Angles(10,1.5,0),1)
 
            Sound3:Play()
 	        end)       
 
    BV.Parent = RootPart
 
    wait(1)
 
 
    Trail.Enabled = false
 
 
    BV:Destroy()
 

plr.Character.Humanoid.WalkSpeed = 16
    wait(2)
        Sound1:Stop()
    Sound4:Stop()
end)

5 comments

0

Change local Char = player.Character to local Char = player:WaitForChild("Character") ? Since the character isn't loaded yet when the script is working

0

15:25:40.943 - ServerScriptService.Script:5: attempt to index nil with 'WaitForChild'

0

Is your script a local script? cause you can't use localplayer on normal script (Also local script doesn't work in ServerScriptService)

0

its script

2 answers

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

local 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.

1 comment

0

i sent the local script in answers you mind checking it out

heres the local script

local ReplicatedStorage= game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local Sound1 = script.Parent.WaterSound1
local Sound4 = script.Parent.WaterSound4
local Sound3 = script.Parent.WaterSound3
local Debris = game:GetService("Debris")
 
 
local player = game.Players.LocalPlayer
 
local char = player.Character
 
local rp = char:WaitForChild("HumanoidRootPart")
 
 
local WaterWheelEffects = ReplicatedStorage:WaitForChild("WaterWheel")
local plr = game.Players.LocalPlayer
 
local Char = plr.Character or plr.CharacterAddeed:Wait()
local Player = game.Players.LocalPlayer
 
local Character = Player.Character or script.Parent
local Humanoid = Character.Humanoid
local UserInputService = game:GetService("UserInputService")
 
local AnimationID = 'rbxassetid://4906842204'
local key = 'R'
local debounce = true
 
UserInputService.InputBegan:Connect(function(Input, IsTyping)
 
    if  IsTyping then return
 
end
 
    if Input.KeyCode == Enum.KeyCode[key] and debounce == true then
      debounce = false
          RemoteEvent:FireServer(AnimationID, Sound1, Sound4, Sound3)
    end
end)

1 comment

0

Why do you have 2 definitions of the LocalPlayer? Remove one and it should work.

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