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

How do I locate Humanoid in this script ?

local USI = game:GetService("UserInputService")
local damage = 50
local Handle = script.Parent.Handle
local rep = game.ReplicatedStorage
local CanSprint = rep.BoolValues.CanSprint

script.Parent.Equipped:Connect(function(equip)
	local plr = equip.Parent
	local Humanoid = plr:FindFirstChild("Humanoid")
	
	Handle.Transparency = 1
	
	USI.InputBegan:Connect(function(input)
		local keycode = input.KeyCode 
		if keycode == Enum.KeyCode.F then
			Handle.Transparency = 0
			Humanoid.WalkSpeed = 40
			CanSprint = false
			
		end
	end)
	
	USI.InputEnded:Connect(function(input)
		local keycode = input.KeyCode
		if keycode == Enum.KeyCode.F then
			Handle.Transparency = 0
			Humanoid.WalkSpeed = 16
			CanSprint = true
		end
		
	end)
	
end)

3 answers

Instead of

local plr = equip.Parent
local Humanoid = plr:FindFirstChild("Humanoid")

try doing

local plr = game:GetService("Players").LocalPlayer
local Humanoid = plr.Character:FindFirstChild("Humanoid")

3 comments

0

didnt work :(

0

also is it a localscript or a server script?

0

server script

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

1 comment

0

This is in a local script, btw.

try doing this:

script.Parent.Equipped:Connect(function()
	local plr = script.Parent.Parent
	local Humanoid = plr:WaitForChild("Humanoid",0.1)
	-- rest of your code here
end)

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