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

Why does it say ca is a nil value when it is not? is this a bug

local p = game.Players.LocalPlayer
p.CharacterAdded:Connect(function(ch)
	ca = p.Character
end)
local m = p:GetMouse()
local UIS = game:GetService("UserInputService")
ca.Humanoid.WalkSpeed = 25



attempt to index a nil value, line 8

1 answer

✓ Accepted answer

CharacterAdded fires in the same tick as the character begins to exist.adding everything to it and setting it as the player's character will not happen when the event is called.

I recommend instead of that, doing this.

local p = game.Players.LocalPlayer
local ca = p.Character or p.CharacterAdded:Wait()

local m = p:GetMouse()
local UIS = game:GetService("UserInputService")
ca.Humanoid.WalkSpeed = 25

ca will be the character no matter what, as it will wait for it to get added if it needs to.

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