How do I fix my script that spawns a brick on the player?

Hello, I am making a bossfight for my game and I want to make multiple attacks that spawn things where the player is so they have to well, move a bit. However the slight issue is I don’t know what I’m doing wrong in the script as the part’s position doesn’t change to the player’s position.

local TargetPart = game.Workspace:WaitForChild("HumanoidRootPart")
local XValue = TargetPart.Position.X
local ZValue = TargetPart.Position.Z

script.Parent.Position = Vector3.new(XValue, 3.25, ZValue)

What did I do wrong here?

1 Like

local TargetPart = game.Workspace:WaitForChild("HumanoidRootPart")

Are you expecting a HumanoidRootPart from the workspace? Wasn’t that supposed to be you waiting for the HumanoidRootPart of the player’s character?

1 Like

Hmm, It’d make more sense to find the player but the issue is I don’t know what’d I’d write.

I think you should do this in a LocalScript instead of a normal Script. And then type:

local player = game.Players.LocalPlayer
repeat wait(1) until player.Character ~= nil -- Waiting for player's character
local TargetPart = player.Character:WaitForChild("HumanoidRootPart")

local XValue = TargetPart.Position.X
local ZValue = TargetPart.Position.Z

script.Parent.Position = Vector3.new(XValue, 3.25, ZValue)

Try this and let me know if it works.

You should use .CFrame instead

image

It results in this and in a LocalScript it just doesn’t do anything.

Try this, hopefully should work for you @2147483647:

local players = game:GetService("Players")
local TargetPart = players.LocalPlayer:WaitForChild("HumanoidRootPart")
local XValue = TargetPart.Position.X
local ZValue = TargetPart.Position.Z

script.Parent.Position = Vector3.new(XValue, 3.25, ZValue)

image I tried this one and it just gave me this error.

Can you just check which folder HumanoidRootPart is stored in your player? Can’t quite remember.

I’m guessing you’re doing this on the server?

Hmm that could be the issue, should of checked that before.

No, no, why are you trying to check if the HumanoidRootPart is a child of the player? It’s part of the character.

You get the error because LocalPlayer is not a child nor a property of the service Players while you’re running it on the server.

Hmm @2147483647, try this instead [not fully aware on how to get a players model from workspace]:

local workspace = game:GetService("Workspace")
local TargetPart = workspace.LocalPlayer:WaitForChild("HumanoidRootPart")
local XValue = TargetPart.Position.X
local ZValue = TargetPart.Position.Z

script.Parent.Position = Vector3.new(XValue, 3.25, ZValue)

If this doesn’t work, try replacing what is currently stored in the workspace variable to simply game.Workspace.

… This won’t work either chief.

Is it the local workspace? Couldn’t remember if it’s a service or not.

The entire script is incorrect, you need to find a way to grab the player that is in the “bossfight” and then use the players Character to get their HumanoidRootPart.

The script he attached was:

All I can think of is adding .LocalPlayer next to game.Workspace. @2147483647 please tell me if this works.

That doesn’t even make sense, if you don’t know how to script, please don’t confuse him more.

I do know how to script a little bit, I’m trying to help in the best possible way.