Gravity Coil script gets disabled when being cloned

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)

try and clone the coil from replicated storage instead

It clones in game but doesn’t fire the script for the gravity coil.

Another problem that I just ran into is that the gear doesn’t even save when you die. And yes, I added a CharacterAdded event.

Put it in the player’s StarterGear to make it stay when they die.

But I want it to be a gamepass item. And when I did this before, it saved when the player died.

put it in the starter gear but make it so that the local script in the coil will destroy the coil if the player doesn’t have the gamepass

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.

It cloned successfully but it still breaks the tools code when cloned.

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)
1 Like

Actually we have another problem where once you equipped the gravity coil and you unequipped it, it never goes back to the normal jumppower.

try cloning it to plr.StarterGear

Did you read the script in one of these replies?

Ah sorry. I will try looking closely next time.

1 Like

It works fine for me, I’m not sure what the issue is.

So you’re saying that you don’t get an error saying, humanoid is not a valid member of workspace

Can you send a screenshot of tool and the children inside it?

sddfgfdtrtttt erreretr

Hmm, mine is set up the same and I get no error.

For the humanoid part it’s getting underlined as a warning
srrsvft