Attempt to index nil with walkspeed

Hello, for context, each time a dialogue starts your character should be frozen in place. After the dialogue ends, you’ll be able to move again. I have tried to fix this several times, and it’s either the dialogue interface pops up, your character doesn’t freeze and the dialogue is simply “Label”. Or nothing happens, not even the dialogue interface shows up.

Here is my script, I am relatively new to scripting and there is only one set of dialogue for now. My game is still in development, there is a script inside of an invisible part in workspace which fires a remote event:

-- // Variables // --
local replicatedStorage = game.ReplicatedStorage
local events = replicatedStorage.Events

local dialogueBox = script.Parent
local dialogue = dialogueBox.Dialogue
local speaker = dialogueBox.Speaker

local sounds = workspace.Sounds
local dialogueSound = sounds.Dialogue

local currentDialogue = nil
local currentSpeaker = nil

local shortDelay = 3
local mediumDelay = 5
local longDelay = 7

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local character = localPlayer.Character
local humanoid = localPlayer:FindFirstChild("Humanoid")

-- // Functions // --
function typewrite()
	for i = 1, #currentDialogue do
		dialogue.Text = string.sub(currentDialogue, 1, i)
		dialogueSound:Play()
		wait(0.06)
	end
end

function handleDialogueStart()
	dialogueBox.Visible = true
	speaker.Text = currentSpeaker
	humanoid.WalkSpeed = 0
end

function handleDialogueEnd()
	dialogueBox.Visible = false
	currentDialogue = nil
	currentSpeaker = nil
	humanoid.WalkSpeed = 10
end

-- // Dialogues // --
events.DumpsterEncounter.OnClientEvent:Connect(function()
	currentSpeaker = "You"
	handleDialogueStart()
	currentDialogue = "Well, the dumpsters are blocking my way. How am I going to get around this? I can't swim."
	typewrite()
	wait(shortDelay)
	currentDialogue = "This is what happens when you work in the sewers, occasional floods... goddammit."
	typewrite()
	wait(shortDelay)
	handleDialogueEnd()
end)

try

local humanoid = localPlayer:WaitForChild("Humanoid")

I’ve tried that, it doesn’t work as well. The dialogue interface doesn’t show up and your character doesn’t even freeze. No errors in the output as well.

The Humanoid is located inside player characters, therefore you must replace localPlayer:FindFirstChild("Humanoid") with character:WaitForChild("Humanoid").

Why not try:

function typewrite(dialogue)
--function

typewrite(--Your Text Here--)
--When calling

Instead of having a variable called Dialogue.

You cant do local player in server script try do game. Players. PlayerAdded

It still hasn’t worked, I noticed I had the character variable set up already so thanks for reminding me. But it still didn’t work, also, why do I need WaitForChild?

Is it local script? Or a normal

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

It’s in StarterGui, and this is how I arranged it.
image

Set the ScreenGui.ResetOnSpawn property to true and the character variable to:

local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()

I checked and ResetOnSpawn is true, I’ve also tried doing that with the character variable but it still didn’t work.

Are you using :WaitForChild for the humanoid? And does the console show any errors? Perhaps a new error occurs not related to that.

I am so stupid, after doing what you told me to with the character variable and changing FindFirstChild to WaitForChild it actually worked. Thanks.

Nevermind, it worked twice then I decided to close the output tab and playtested it again, after that, it stopped working.

Edit: Okay, sometimes it works, sometimes it doesn’t.