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!
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)