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

How do I stop this placement system from moving?

I have been trying to make a placement system and I have been trying for a while. I cannot find anything to stop it from moving.

Thanks for helping!

Code:

wait(0.01)
local model = game.Lighting.Handgunner
local input = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
 
input.InputBegan:connect(function(inp,GPE)
    if inp.KeyCode == Enum.KeyCode.P then
	model.Parent = game.Workspace.CurrentCamera
    input.InputChanged:connect(function(ip)
       
    if  ip.UserInputType == Enum.UserInputType.MouseMovement then
 
        local currentPos = model:GetPrimaryPartCFrame() 
        model:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.X,currentPos.Y,mouse.Hit.Z)) 
        
            print("Movement Detected") 
end
end)
end
    end)

1 answer

Why do you try setting the model's primary part cframe on every frame using RenderStepped. It will look a lot smoother.

local RunService = game:GetService("RunService")
local model = workspace.model
local stillPlacing = true
local myMouse = game.Player.LocalPlayer:GetMouse()

--trigger event to start placement system

while stillPlacing == true do
	model:SetPrimaryPartCFrame(CFrame.new(myMouse.Hit.Position))
	RunService.RenderStepped:wait()
end

5 comments

0

BUT im not trying to set it into a certain spot im trying to make it like a TD placement system

0

But you are setting it to a certain spot, that's why you call :SetPrimaryPartCFrame(). I don't understand.

0

wait

0

it gives the error 'player is not a valid member of datamodel'

0

sorry it should be "Players"

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