I am trying to make a thing that if when someone joins or dies, if they are a developer or have the VIP gamepass then it will give them double WalkSpeed and double JumpPower.
Here is my full normal script in workspace:
01 | local ms = game:GetService( "MarketplaceService" ) |
02 | local id = 9148194 |
03 | game.Players.PlayerAdded:Connect( function (plr) |
04 | local char = plr.Character |
05 | local hum = char:WaitForChild( "Humanoid" ) |
06 | if ms:UserOwnsGamePassAsync(plr.UserId,id) then |
07 | hum.WalkSpeed = 32 |
08 | hum.Died:Connect( function () |
09 | wait( 3 ) |
10 | hum.WalkSpeed = 32 |
11 | end ) |
12 | elseif plr.UserId = = 950965355 or plr.UserId = = 714312166 then |
13 | hum.WalkSpeed = 32 |
14 | hum.JumpPower = 100 |
15 | hum.Died:Connect( function () |
Please tell me what is wrong. Thanks in advance!
it's because the character hasn't loaded yet when the script tried looking for it. also, you tried to set the walkspeed of the humanoid after the player has respawned, which will also cause error, because the old humanoid doesn't exist after respawning. i've added plr.CharacterAdded
so that it fires each time the player respawns.
01 | local ms = game:GetService( "MarketplaceService" ) |
02 | local id = 9148194 |
03 |
04 | game:GetService( 'Players' ).PlayerAdded:Connect( function (plr) |
05 | repeat wait() until plr and plr.Character and plr.Character:FindFirstChild( 'Humanoid' ) |
06 | local char,hum = plr.Character,plr.Character.Humanoid |
07 | if ms:UserOwnsGamePassAsync(plr.UserId,id) then |
08 | hum.WalkSpeed = 32 |
09 | plr.CharacterAdded:Connect( function (char) |
10 | repeat wait() until char and char:FindFirstChild( 'Humanoid' ) |
11 | local newhum = char.Humanoid |
12 | newhum.WalkSpeed = 32 |
13 | end ) |
14 | elseif plr.UserId = = 950965355 or plr.UserId = = 714312166 then |
15 | hum.WalkSpeed = 32 |