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

How to allow use of a shift-sprint script when Game Pass owned?

Asked by 5 years ago

Hi! First question here. Amazing this website exists.

In my game, I would like to sell a Game Pass which makes the use of a 'shift key to sprint' script possible. I have the script set up in my StarterGui already (thanks to the free models), but I'm not sure how to 'deny' the use of it to players not owning the Game Pass.

**The script, in case anyone would like to know: **

wait()local Player=game.Players.LocalPlayer local Mouse = Player:GetMouse() local Speed = 50 local Humanoid = Player.Character:WaitForChild("Humanoid") local OrigSpeed = Humanoid.WalkSpeed

Mouse.KeyDown:connect(function(Key)local Code=Key:byte()if(Code==48)then Humanoid.WalkSpeed = Speed end end) Mouse.KeyUp:connect(function(Key)local Code=Key:byte()if(Code==48)then Humanoid.WalkSpeed = OrigSpeed end end)

Thanks a lot!

  • Allineate
0
Put the script in code block man. Launderer 343 — 5y

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You can place the script in somewhere like ServerStorage and then run it only on the players who have purchased the gamepass once they join, by cloning it and parenting it to their PlayerGui.

Server script:

local gamePassId = 123
local theScript = game:GetService("ServerStorage").theScript

game:GetService("Players").PlayerAdded:Connect(function(plr)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamePassId) then
        theScript:Clone().Parent = plr:WaitForChild("PlayerGui")
    end
end)

Btw you should use UserInputService.InputBegan instead of Mouse.KeyDown.

The localscript:

local plr = game:GetService("Players").LocalPlayer

script.Parent = plr:WaitForChild("PlayerScripts") --so it keeps running after respawn

game:GetService("UserInputService").InputBegan:Connect(function(iobj, gp)
    if gp then return end
    if iobj.KeyCode == Enum.KeyCode.LeftShift and plr.Character then
        plr.Character:WaitForChild("Humanoid").WalkSpeed = 50
    end
end)

game:GetService("UserInputService").InputEnded:Connect(function(iobj, gp)
    if gp then return end
    if iobj.KeyCode == Enum.KeyCode.LeftShift and plr.Character then
        plr.Character:WaitForChild("Humanoid").WalkSpeed = 16
    end
end)
0
This is amazing! Thank you so much for this. I got it working within 2 minutes. Allineate 22 — 5y
Ad

Answer this question