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

Is it Possible to make a GAMEPASS from a KEYDOWN function?

Examples: Shift to run space to jump

If I can, where do I place it?

Is it a local script?

A regular Script?

I've tried making one using a script in the ServerScriptService and it's not working out for me.

Thanks for helping in advance. :)


game.Players.PlayerAdded:connect(function(player)
 player.CharacterAdded:connect(function(character)
  if game.GamePassService:PlayerHasPass(player,--GP HERE) then

--i PUT MY CODE HERE


end)

end)

4 comments

0

what...

0

Are you saying I wrote it wrong? I'm not even sure what I did wrong, thanks if you get back to me

0

^ Nah, just a reference. :P

1 answer

✓ Accepted answer

Yes, of course, but you'll need a RemoteFunction to return whether you own the game pass from a LocalScript. The jump Bindable should also be disabled. You can also view this for some extra knowledge.

LocalScript in StarterCharacterScripts

local me = game.Players.LocalPlayer
local char = me.Character or me.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local RemoteFunction = script:WaitForChild('RemoteFunction')
local UserInputService = game:GetService('UserInputService')
local canJumpAndRun = RemoteFunction:InvokeServer()
-- Invokes the remote function that return whether you own the game pass
	-- only checks when they load though, so if they buy it after, they'll need to reset. 
	
local ContextActionService = game:GetService('ContextActionService')
ContextActionService:UnbindAction("jumpAction")


local maximizedWalkSpeed = 30
local defaultWalkSpeed = 16

UserInputService.InputBegan:Connect(function(input)
	-- Something was pressed
	if input.KeyCode == Enum.KeyCode.Space then 
		-- Will need a loop to check if we're holding to keep jumping
		humanoid.Jump = (canJumpAndRun and true or false)
	elseif input.KeyCode == Enum.KeyCode.LeftShift then 
		humanoid.WalkSpeed = (canJumpAndRun and maximizedWalkSpeed or defaultWalkSpeed)
	end
end)

UserInputService.InputEnded:Connect(function(input)
	-- Key up
	if input.KeyCode == Enum.KeyCode.LeftShift then 
		humanoid.WalkSpeed = defaultWalkSpeed
	end
end)

In a Script inside of the LocalScript

local RemoteFunction = Instance.new("RemoteFunction", script.Parent)
local GamePassService = game:GetService('GamePassService')
local GamePassId = 100000

function RemoteFunction.OnServerInvoke(player)
	return GamePassService:PlayerHasPass(player, GamePassId)
end

1 comment

0

Thanks

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