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

Why is this part still moving?

Alright, let's recreate the situation. I have a LocalScript in my StarterPack and a normal Script in my ServerStorage. The LocalScript creates a brick at the mouse pointer when the mouse button is pressed and the Script is used to keep the part at it's position, but every time I walk by, it moves up.

-- LocalScript in StarterPack
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Up:connect(function()
	local Part = Instance.new("Part", Workspace)
	Part.CanCollide = true
	Part.Anchored = true
	Part.Size = Vector3.new(1,10,10)
	Part.Position = mouse.Hit.p)
	local Script = game.ServerStorage.Script:Clone()
	Script.Parent = Part
end)
-- Script in ServerStorage
local Part = script.Parent
while wait() do
	if Part.Position.y > 0 then
		Part.Position = Vector3.new(Part.Position.x, 0, Part.Position.z)
	end
end

Does anyone know how I can make a Part stay at it's position, even though the player spawned it on top of his head?

1 answer

✓ Accepted answer

Since you have "while wait() do" the part keeps moving?

I would just do this.

--LocalScript in StarterGear or StarterGui.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:connect(function() --Your call statement.
local Part = Instance.new("Part", game.Workspace) --Creates your brick and puts it into game.Workspace.
Part.Anchored = true
Part.CanCollide = true
Part.Transparency = 0
Part.BrickColor = BrickColor.new("Bright red") --Any color, Just lets you see your brick better.
Part.Size = Vector3.new(1, 10, 10)
Part.Position = Mouse.Hit.p
local SetPosition = Part.Position
while wait() do
Part.Position = SetPosition
end
end)

3 comments

0

Tell me if that works!

0

Nice, that works, It's just a small part of a bigger game, so I just recreated the situation. But it works in my game too. Thank you.

0

I thought that putting a while wait loop would make the script become stuck at that point.

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