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

What's wrong with this walkspeed gamepass script?

local MegaVipGamepassId = 0 -- Gamepass Id

game.Players.PlayerAdded:connect(function(Player)
	Player:WaitForDataReady()
	if game:GetService("GamePassService"):PlayerHasPass(Player, MegaVipGamepassId) then
		coroutine.resume(coroutine.create(function()
			while wait() do
				repeat wait() until Player.Character ~= nil 
				Player.Character.Humanoid.WalkSpeed = 32
			end
		end))
	end
end)

I'm getting this error:

Humanoid is not a valid member of Model Script 'ServerScriptService.Script', Line 9 Stack End

2 comments

0

try Player.Character:WaitForChild("Humanoid").WalkSpeed = 32.

0

^The WaitForChild method doesn't return the child you're waiting for, it returns the time it took for the child to not be nil. So by you saying that it's like saying wait(1).WlkSpeed = 32

1 answer

✓ Accepted answer

I suggest you don't use loops, they're very inefficient

An alternative to using loops would be just checking everytime their character adds - with a CharacterAdded event. This will also eliminate the problem of having to rejoin when you buy the pass.

local passId = 0 -- Gamepass Id
local speed = 32 --The speed to add

game.Players.PlayerAdded:connect(function(Player)
	plr.CharacterAdded:connect(function(char)
		if game:GetService("GamePassService"):PlayerHasPass(Player, passId) then
			repeat wait() until char:FindFirstChild('Humanoid') ~= nil
			char.Humanoid.WalkSpeed = speed
		end
	end)
end)

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