What do you want to achieve? Keep it simple and clear!
I made a gamepass that give a rocket launcher to the player.
What is the issue? Include screenshots / videos if possible!
It works the first time but on the second it comes up with this error;
11:50:45.841 The Parent property of Handle is locked, current parent: NULL, new parent MegaLauncher - Server - Script:9
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked through the DevForum for help but nothing worked. Like Destroying the tool did not work.
Here’s my code;
local Mega = script.MegaLauncher:Clone()
local Handle = script.Handle:Clone()
game.Players.PlayerAdded:Connect(function(plr)
local PLrId = plr.UserId
plr.CharacterAdded:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PLrId, 26834191) then
Handle.Parent = Mega
Mega.Parent = plr.Character
end
end)
end)
The handle kept deleting itself so I did this and it worked. But still not fixed.
I do recommend to add a bool to check if player really owns the gamepass. But it is optional for you to do the same thing.
local mps = game:GetService("MarketPlaceService")
local haspass = false
game.Players.PlayerAdded:Connect(function(player)
haspass = mps:UserOwnsGamePassAsync(player.UserId, 000000)
if haspass then
-- give player tool/ability
else
-- if player doesn't match with the gamepass ID then haspass will return false
end
end)
You should use the CharacterAppearanceLoaded event if you want a Character to fully load all of it’s Children so that you can properly parent your Tool
Also, if you want a Player to equip a weapon once given, call the Humanoid:EquipTool() function so that it’s automatically parented to your Character Model inside the workspace
local GamepassID = 26834191
local Players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")
local Mega = script:WaitForChild("MegaLauncher")
local handle = script:WaitForChild("Handle")
-- There is no need to be cloning it upon starting the script in the first place, it's better to clone it if the Player has the Gamepass to let it know when to give it
Players.PlayerAdded:Connect(function(Plr)
local PlrId = Plr.UserId
Plr.CharacterAppearanceLoaded:Connect(function(Chr)
local Humanoid = Chr:WaitForChild("Humanoid")
if MPS:UserOwnsGamePassAsync(PlrId, GamepassID) then
local HandleClone = Handle:Clone()
HandleClone.Parent = Mega
local ToolClone = Mega:Clone()
ToolClone.Parent = Chr
end
end)
end)