Localscript is not enabling from script

I’m Trying to make a gamepass that when you buy it, the jumpPower will increase instantly to 100 from 50

I’m using a script in workspace to to activate the localscript thats inside StarterCharacterScripts:

local scr = game.StarterPlayer.StarterCharacterScripts.jump
local work = game.Workspace
local ID = "rbxassetid://829025029"
local marketplace =  game:GetService("MarketplaceService")
-- it starts
work.ChildAdded:Connect(function(child)
	if child.Name == "PlayerJump" then
		if marketplace:UserOwnsGamePassAsync(child.UserId, 829025029) then -- id from gamepasses
			scr.Enabled = true
		end
	end
end)

This is the localscript in StarterCharacterScripts: (disabled script)

local humanoid = script.Parent:FindFirstChild('Humanoid')
humanoid.UseJumpPower = true
humanoid.JumpPower = 100

For some reason, The localscript is not enabling when the first script runs, and it should make the JumpPower to 100 if the gramepass is purchased

This is the localscript that makes the button show a buying prompt

local jumppowerpass = script.Parent
local ID = "rbxassetid://829025029"
local marketplace =  game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer

jumppowerpass.MouseButton1Click:Connect(function()
	marketplace:PromptGamePassPurchase(player, 829025029)
end)

marketplace.PromptGamePassPurchaseFinished:Connect(function(player, gamepassID, purchased)
	if purchased and gamepassID == 829025029 then
		script.Parent.Parent.Visible = false
	end
end)

Any help?

2 Likes

Well your first line of code should explain what went wrong:

You’re enabling the script which isn’t actually a parent of any player. To understand why, you have to look at how the behavior of StarterCharacterScripts works:

The StarterCharacterScripts class stores scripts to be parented in a player’s Player.Character, when they spawn.

The script is cloned into the character, meaning that the original script you’ve referenced does absolutely nothing. To fix it, you just need to listen for when the Character is added and modify the Humanoid run values from there. (Make sure to have PlayerCharacterDestroyBehavior set to Enabled in the workspace so you don’t have any memory leaks)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.