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

Why is this part still moving?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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)
0
Tell me if that works! kevinjurden 10 — 10y
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. damagex443 325 — 10y
0
I thought that putting a while wait loop would make the script become stuck at that point. damagex443 325 — 10y
Ad

Answer this question