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

Change Walkspeed OnTouch if GamePass?

Hey there so i have this script and its supposed to change your walk speed on touch, if you own a gamepass. I dont know if ive done this wrong or anything, thanks.

local id = 7549271
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and ido == id then
		local db = true
		script.Parent.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid")~= nil then
				if db == true then
					db = false
					plr.Character.Humanoid.Walkspeed = 40
				end
			end
		end)
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId. id) then
			local db = true
			script.Parent.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChild("Humanoid")~= nil then
					if db == true then
						db = false
						char.Humanoid.WalkSpeed = 40
					end
				end
			end)
		end
	end)
end)

1 answer

✓ Accepted answer

Use this:

local id = 7549271--The id of the gamepass

game.Players.PlayerAdded:Connect(function(plr)--Connects to the PlayerAdded event.
    plr.CharacterAdded:connect(function(char)--Connects to the CharacterAdded event.
        local db = true
        script.Parent.Touched:Connect(function(hit)--Connects to the Touched event
            if hit.Parent = char then--Makes sure that its the correct character
                   if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,id) then--Checks if the player has the GamePass
                    if db == true then--Checks if it is true
                        db = false--Sets it to false, this way the script can not run this code
                        char.Humanoid.WalkSpeed = 40--Sets the walkspeed to 40
                        wait(1)--The amount of time before it can do this code again
                        db = true--Sets it to true, this way the script can run this code again
                    end
                end
            end
        end)
    end)
end)

2 comments

0

Ok so it works, but only once. How would I change this?

0

Fixed it

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