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

Why wont the brick's CFrame follow me?

Asked by 4 years ago

This script works like it's supposed to but when i move and activate the tool again it still positions itself in the same spot as it did the first time i clicked. How do i make it so that if i move and click it again it spawns at my new position?

wait(.5)
Player = game.Players.LocalPlayer
Character = Player.Character
Humanoid = Character.Humanoid
Tool = script.Parent

Tool.Activated:Connect(function()
    local brick = Instance.new("Part")
    brick.Parent = game.Workspace
    brick.Size = Vector3.new(1, 5, 5)
    brick.Anchored = true
    brick.CFrame = CFrame.new(Character.LeftFoot.CFrame, 10 , Character.LeftFoot.CFrame)
end)

0
you have 2 CFrames inside of CFrame.new.. that's not right ryan32t 306 — 4y
0
Error messages? cmgtotalyawesome 1418 — 4y
0
at line 12 were your setting the CFrame do: CFrame.new(brick.Position,Character.LeftFoot.Position) mantorok4866 201 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hello. I'm not sure of my answer, but I think the problem is that at lines 2 and 3, you did a variable that get the player and his character. Then, at line 12, you used those variables to spawn that part. But the lines 2 and 3 never RE-NEW, cuz you didn't put them inside a function. So the script will spawn the block every time at the same position. You can put the varibales inside the function like this:

local Tool = script.Parent

Tool.Activated:Connect(function()
    local Player = game.Players.LocalPlayer
    local Character = Player.Character
    local brick = Instance.new("Part")
    brick.Parent = game.Workspace
    brick.Size = Vector3.new(1, 5, 5)
    brick.Anchored = true
    brick.CFrame = CFrame.new(Character.LeftFoot.CFrame, 10 , Character.LeftFoot.CFrame)
end)

Also, you wrote at line 12, the CFrame of the two feet. It should be the X, Y or Z value of their positions.

local Tool = script.Parent

Tool.Activated:Connect(function()
    local Player = game.Players.LocalPlayer
    local Character = Player.Character
    local brick = Instance.new("Part")
    brick.Parent = game.Workspace
    brick.Size = Vector3.new(1, 5, 5)
    brick.Anchored = true
    brick.CFrame = CFrame.new(Character.LeftFoot.Position.X, 10, Character.LeftFoot.Position.Z)
end)

Hope this helped!

Ad

Answer this question