It doesn’t update properly because you are only sending the remote once, which means it’s just repeatedly positioning itself to the same spot.
Personally though, I’d make the preview appear on the client instead. Then once you’ve clicked, fire a remote to the server and place the part there.
I believe you are still setting the NewPart position to your old mouse position. It doesn’t update with your new one because MousePos is a reference to your old mouse position.
You wanna make it something like this
if NewPart.Parent == workspace then
repeat
print("Repeating")
MousePos2 = Mouse.Hit.Position -- this updates the variable to your new mouse position
NewPart.Position = MousePos2
task.wait()
until Click
end
Well, this might not solve your problem, but I wanna tell you that registering Mouse.Button1Up every time when ImageButton is activated gonna cause a memory leak if done a lot of times.
if NewPart.Parent == workspace then
repeat
print("Repeating")
local MousePos2 = Mouse.Hit.Position
NewPart.Position = MousePos2
NewPart.Parent = workspace
wait()
until Click
end
It’s not appearing, the “NewPart” isn’t even in the workspace
Probably because it’s getting destroyed immediately after it gets created. You may wanna rewrite the repeat until section of your code and only let it repeat until you’ve actually clicked, instead of checking the event itself.
-- In the Button or StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ButtonEvent = ReplicatedStorage.ButtonEvent
local Mouse = Players.LocalPlayer:GetMouse()
local Button = -- your button location
Button.MouseButton1Up:Connect(function()
local MousePos = Mouse.Hit.Position
ButtonEvent:FireServer(MousePos)
end)
Script
-- In ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ButtonEvent = ReplicatedStorage.ButtonEvent
ButtonEvent.OnServerEvent:Connect(function(Player, MousePos)
print("Fired")
local NewPart = Instance.new("Part")
NewPart.Size = Vector3.new(2, 2, 2)
NewPart.Anchored = true
NewPart.Transparency = 0.5
NewPart.Position = MousePos
NewPart.Parent = workspace
end)