Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does it say the parent property of bodyposition is locked?

local ignore = game.Players.LocalPlayer.Character
mouse = game.Players.LocalPlayer:GetMouse()
char = game.Players.LocalPlayer.Character
--beam = Ray.new(char.Torso.Position,(mouse.Hit.p*30))

hold = false -- we want to make sure we can ungrapple
body = game.Workspace.Forces.BodyPosition -- we need a force


 function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then
			hold = true
			while hold do 
			local beam = Ray.new(char.Torso.Position,(mouse.Hit.p*5))
			body:Clone()
			body.Parent = char.Torso
			wait()
		end
	end
end 
function onKeyRelease(inputObject,gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.Q then
        hold = false    
		body:Destroy()
	end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
game:GetService("UserInputService").InputEnded:connect(onKeyRelease)

why wont it boost me when i press Q again... i made sure its cloning..

2 comments

0

To answer your title, this error usually occurs when you try finding the Parent Property of an object which has been destroyed using the method :Destroy()

0

@randomsmileyface: "when you try finding the Parent Property" should say "when you try setting the Parent Property"

1 answer

✓ Accepted answer

Hey Aeike!

So, your issue is that when you're deleting the object that you want to copy, as well as parenting it, and you never actually use the copy itself!

local ignore = game.Players.LocalPlayer.Character
local mouse = game.Players.LocalPlayer:GetMouse()
local char = game.Players.LocalPlayer.Character
--local beam = Ray.new(char.Torso.Position,(mouse.Hit.p*30))

local hold = false -- we want to make sure we can ungrapple
local body = game.Workspace.Forces.BodyPosition -- we need a force
local body_clone = nil -- Set up a variable for your body clone that is accessible

local function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Q then
            hold = true
            while hold do 
            local beam = Ray.new(char.Torso.Position,(mouse.Hit.p*5))
            body_clone = body:Clone() -- Set your clone to something.
            body_clone.Parent = char.Torso
            wait()
        end
    end
end 
local function onKeyRelease(inputObject,gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.Q then
        hold = false 
	if(body_clone) then   -- Make sure that the clone is instantiated
        	body_clone:Destroy()
		body_clone = nil
	end
    end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
game:GetService("UserInputService").InputEnded:connect(onKeyRelease)

Keep in mind that this method will only allow you to create one beam at a time, since they all get destroyed immediately when your release Q.

Hope this helps! =)

This discussion is preserved as it was. New answers, comments, and votes are closed.