Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
what... 0msh 333 — 6y
0
Are you saying I wrote it wrong? I'm not even sure what I did wrong, thanks if you get back to me robloxquestionnaire1 30 — 6y
0
^ Nah, just a reference. :P TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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
0
Thanks robloxquestionnaire1 30 — 6y
Ad

Answer this question