Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Aeike 9
6 years ago
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..

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() randomsmileyface 375 — 6y
0
@randomsmileyface: "when you try finding the Parent Property" should say "when you try *setting* the Parent Property" chess123mate 5873 — 6y

1 answer

Log in to vote
0
Answered by
saenae 318 Moderation Voter
6 years ago

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! =)

Ad

Answer this question