I’m trying to make a speed coil gamepass but I ran into an issue with the UserOwnsGamepass function where when the speed coil gets cloned into the players backpack, it doesn’t work. But when it’s in startergear, it works just fine.
Script for the gamepass:
local GPS = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:Connect(function(plr)
if GPS:UserOwnsGamePassAsync(plr.UserId,REDACTED) then
local Speed = game:GetService("ServerStorage"):FindFirstChild("GravityCoil"):Clone()
Speed.Parent = plr:WaitForChild("Backpack")
end
end)
Script for the gravity coil:
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
script.Parent.Equipped:Connect(function()
humanoid.JumpPower = 80
end)
script.Parent.Unequipped:Connect(function()
humanoid.JumpPower = 50
end)
So couple of issues here. For starters, you have an issue where you are defining the player’s character. player.CharacterAdded:Wait() is correct, but you should be doing player.Character or player.CharacterAdded:Wait() incase the player’s character is already loaded. With the current method of defining the player’s character, if the character is already loaded (which it is because they will not equip the tool automatically on join) the script will never run.
Now, in the server script, you should not be using :FindFirstChild() and :WaitForChild() the way you are. This doesn’t have much to do with the functionality of your code, but it is unneeded because you are not checking for it’s existence after using either function.
local GPS = game:GetService("MarketplaceService")
local serverStorage = game:GetService("ServerStorage")
game:GetService("Players").PlayerAdded:Connect(function(plr)
if GPS:UserOwnsGamePassAsync(plr.UserId,REDACTED) then
serverStorage.GravityCoil:Clone().Parent = plr.Backpack --Making this a variable was pointless, just do it in one line
serverStorage.GravityCoil:Clone().Parent = plr.StarterGear --Also put in StarterGear to stay on respawn
end
end)
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
tool.Equipped:Connect(function()
humanoid.JumpPower = 80
end)
tool.Unequipped:Connect(function()
humanoid.JumpPower = 50
end)
Hope these changes made sense, and let me know if it still doesn’t work.
I just noticed that you are changing their JumpPower on the client, which should be done on the server so the JumpPower changes are replicated. Try making the script inside the Gravity Coil a server script and use this:
local tool = script.Parent
tool.Equipped:Connect(function()
humanoid = tool.Parent.Humanoid --tool.Parent becomes the player's character when Equipped
humanoid.JumpPower = 150
end)
tool.Unequipped:Connect(function()
humanoid.JumpPower = 50
end)