Hey. I have had a lot of issues regarding the “Parent Property is locked”. I understand this happens when you destroy an object, and attempt to reparent it, however, I don’t see where the issue in my script is ( though it’s quite unorganized since I suck ).
The script is here;
-- Checking variables
local Models = game.ReplicatedStorage.ItemModels
local Flashlight = Models.FlashlightM:Clone()
local Player = game.Players.LocalPlayer
local Equipped = false
local UserInputService = game:GetService("UserInputService")
-- waiting for character
repeat wait() until Player.Character or Player.CharacterAdded:Wait()
local Character = Player.Character
-- Adding Flashlight
function Add_Item()
local Weld = game.ReplicatedStorage.Flashlight:Clone()
Flashlight.Parent = Character
-- make sure its not anchored
if Flashlight.Anchored == true then
Flashlight.Anchored = false
end
Weld.Part0 = Character:WaitForChild("LowerTorso")
Weld.Part1 = Flashlight
Weld.Parent = Flashlight
end
-- Removing Flashlight
function Remove_Item()
if Character:FindFirstChild("FlashlightM") then
Character:FindFirstChild("FlashlightM"):Destroy()
end
end
-- Making it visible in FPS
Flashlight.LocalTransparencyModifier = 0
Flashlight.Changed:Connect(function()
Flashlight.LocalTransparencyModifier = Flashlight.Transparency
end)
-- Flashlight Equip
UserInputService.InputBegan:Connect(function(Input, IsTyping)
if Input.KeyCode == Enum.KeyCode.E and IsTyping == false and Equipped == false then
Add_Item()
local Gui = Player.PlayerGui.SpecialTools
local Image = Gui.Flashlight.LightImage
Image.ImageColor3 = Color3.new(255,0,0)
wait(3)
Equipped = true
else
if Equipped == true then
Equipped = false
local Gui = Player.PlayerGui.SpecialTools
local Image = Gui.Flashlight.LightImage
Remove_Item()
Image.ImageColor3 = Color3.new(255,255,255)
end
end
end)
Legit everything functions, but once I equip the flashlight and unequip it, I can never do it again and I keep getting the error.
