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

Sprinting in a gamepass? I have sprinting how to put it in a gamepass?

I have made it so when you press sprint you run, but I can't figure out how to put it into a game pass so they must own it to be able to sprint. https://gyazo.com/61e8f5371ff50f0c5d14cac3822c1d2a

That is my sprint script if someone could help me out that would be great! Thanks in advance!

2 comments

0

Check the wiki for GamepassService:PlayerHasPass

0

I checked and couldn't find anything...

1 answer

Just add a bool value in them called "CanSprint" or something then create a script not local and add this

local ID = 103728213 --the id to the gamepass
 
game.Players.PlayerAdded:connect(function(plr)
    local CanSprint = plr:FindFirstChild("CanSprint")
    if CanSprint != nil then
	    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
	       CanSprint.Value = true
	    end
    end
end)

and if they don't just add this

local ID = 103728213 --the id to the gamepass
 
game.Players.PlayerAdded:connect(function(plr)
    local CanSprint = plr:FindFirstChild("CanSprint")
    if CanSprint != nil then
	    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
	       CanSprint.Value = true
	else
		CanSprint.Value = true
	    end
    end
end)

and in your sprint script just add before the KeyDown function

 local CanSprint = plr:FindFirstChild("CanSprint")

and then after it add

if CanSprint  != nil then --Checks if it was found
	if CanSprint.Value == true then
		--code
	end
end

And thats it!

Edit: I would suggest using UserInputService to check for keydown its better because Mouse.KeyDown is depricated!

To use UserInputService for your thing you just do this

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		--sprint code
	end
end)

UserInputService.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		--sprint code
	end
end)

5 comments

0

How would I add the keydown for my sprint script?

0

I'm not very good at coding could you walk me through it please?

0

head's up, it's ~= in lua, not !=

0

Yeah i know i'm use to C#

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