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

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

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

1 comment

0

Put the script in code block man.

1 answer

✓ Accepted answer

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)

1 comment

0

This is amazing! Thank you so much for this. I got it working within 2 minutes.

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