Block that changes walkspeed if they have a gamepass

I have this script that changes a players walkspeed on spawn but then when they touch an object it reverts their walkspeed to 16 but once they finish the challenge I want it to perform the check for the gamepasses again without refreshing the player. Is there a way to do this?
This is the script I have on player spawn or respawn:

game.Players.PlayerAdded:Connect(function(player)

 player.CharacterAdded:Connect(function(character)

  if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,8657114) and game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,7888770) then
	character.Humanoid.WalkSpeed = 40

	elseif game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,8657114)then

   character.Humanoid.WalkSpeed = 32
	return
	elseif game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,7888770)then

   character.Humanoid.WalkSpeed = 24
	return
	else
		return


  end

 end)

end)
1 Like

You could make a block at the end of the challenge that perform the check for the gamepass again.

Yes but how would I do that check by addapting the script I have.

If so, one choice is making a while loop. (I don’t know if that’s good but it should work)

I want the walkspeed to only be checked if they reset, refresh or when they step on that block, not all the time.

There exists 2 events that fire, so to help with that, here they are;
Part.Touched and Player.CharacterRemoving

I know about those 2 events but I don’t really understand how to implement them into what I currently have in order for it to work.

On touch, run the ‘if statement’ to check for a gamepass. Then, wallabing, wallaboom. You have yourself what you need.

Ok thanks for your help, I believe I have gotten it to work now, going to post the script in case anyone needs it to help them in the future

game.Players.PlayerAdded:Connect(function(player)

 player.CharacterAdded:Connect(function(character)

script.Parent.Touched:connect(function(p)
local human=p.Parent:findFirstChild("Humanoid")
if human.className=="Humanoid" then
  if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,8657114) and game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,7888770) then
	character.Humanoid.WalkSpeed = 40

	elseif game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,8657114)then

   character.Humanoid.WalkSpeed = 32
	return
	elseif game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,7888770)then

   character.Humanoid.WalkSpeed = 24
	return
	else
		return


  end
end
end)

 end)

end)
1 Like