Door kick not working

script:

script.Parent.Door.Touched:Connect(function(plr)
	print('Touched')
	local humanoid= plr.Parent:FindFirstChild("Humanoid")
	if  humanoid.WalkSpeed>=32 then -- Error
		print("kicked")
		if 	deb == false then
			script.Parent.Door.ProximityPrompt.MaxActivationDistance=0
			openSound:Play()
			frame.CanCollide = false
			tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
			deb = true
			print(deb)
			task.wait(3)
			frame.CanCollide = true
			tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
			deb = false 
			print(deb)
			script.Parent.Door.ProximityPrompt.MaxActivationDistance=32
		end
		end
		
end)

basically I want to create a door kick system, but the program doesn’t recognize the humanoid properly or something like that.
the output says: Attempt to index nil with WalkSpeed.
I know what it means, but I don’t know how to fix it.

im a beginner scripter lol

1 Like

I think you should add a statement “if humanoid then” then check the humanoid walkspeed

1 Like

There are no errors now, but it still doesn’t work. Only the print(“Touched”) part works now.

script.Parent.Door.Touched:Connect(function(plr)
	print('Touched')
	local humanoid= plr.Parent:FindFirstChild("Humanoid")
	if humanoid  then
		if humanoid.WalkSpeed>=32 then-- doesn't register!
		print("kicked")
		if 	deb == false then
			script.Parent.Door.ProximityPrompt.MaxActivationDistance=0
			openSound:Play()
			frame.CanCollide = false
			tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
			deb = true
			print(deb)
			task.wait(3)
			frame.CanCollide = true
			tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
			deb = false 
			print(deb)
			script.Parent.Door.ProximityPrompt.MaxActivationDistance=32
		end
		end
		end
end)

Did you set your character speed then? if yes then how did you do it?

I have a sprint script that sets the player speed to 32.

UserInputService.InputBegan:Connect(function(input,gameProcessedEvent)
	if input.KeyCode == keyboardButton or input.KeyCode == controllerButton and gameProcessedEvent == false then
		pressed = true
		humanoid.WalkSpeed = 32
		
	end
end)

code that enables sprint.

Im not quite sure but i think it is because you set the walkspeed in client which server won’t see that value.
You can add else in the door check (the one that check the speed) to double check (print the humanoid walkspeed)

The sprint script is located in starterCharacterscripts, and I added the code of what you said, print the humanoid walkspeed, and it returned at 16, not 32. So I suspected the same as you.

Yea that is the issue i think you should fire an event to change the humanoid speed instead of client

How should I convert the localscript into a serverscript? And Idk how to fire events properly.

So you create a remote event and name whatever you want in Replicated Storage then create a script inside the ServerScriptService

In local script call the event:

local Event = game.ReplicatedStorage:WaitForChild(“Your Event Name”)

then in UIS.InputBegan instead changing the walkspeed you use:

Event:FireServer(speed) – speed here is the number you want

On the script in server:

Recall the event again:
local Event = game.ReplicatedStorage:WaitForChild(“Your Event Name”)

Event.OnServerEvent:Connect(function(player, speed)
local humanoid = player.character:WaitForChild(“Humanoid”)

   humanoid.WalkSpeed = speed

end)

sorry my phone doesn’t support this website so i can’t write properly

1 Like

Do I put this in the sprint script? Im a little confused on how you explained this, and Im also a noob at scripting

Um yea you replace the “humanoid.WalkSpeed = 32” with Event:FireServer(32)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.