Hi, I'm trying to make a painting system on a canvas so when the player holds down the click button, parts will spawn very fast at the position of their mouse. Only problem is is that the parts wont update to the mouses position in the while loop. That may seem confusing but here's the code:
LocalScript:
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
local Paint = game.ReplicatedStorage.Paint
Mouse.Button1Down:connect(function()
local MousePos = Mouse.Hit.p
local MouseA = Mouse
if Mouse.Target ~= nil then
if Mouse.Target.Name == "Canvas" and "ColorPart" then
Paint:InvokeServer(MousePos, MouseA)
else
print("Cant do that")
end
end
end)
ServerScript:
local Paint = game.ReplicatedStorage.Paint
ButtonPressed = false
Paint.OnServerInvoke = function(player, MousePos, ButtonPressed)
local Folder = Instance.new("Folder", game.Workspace)
ButtonPressed = true
Folder.Name = "Parts"
wait()
if ButtonPressed == true then
while true do
wait()
local Part = Instance.new("Part", game.Workspace.Parts)
Part.Name = "ColorPart"
Part.Position = MousePos
Part.Size = Vector3.new(1.04, 1, 0.05)
Part.BrickColor = BrickColor.new("Really black")
Part.Anchored = true
end
else
print("cant do that")
end
end
If somebody could help me with my problem that would be great! Thanks!

2 comments
Didn't work, this is the error it gave me ServerScriptService.Script:9: attempt to index local 'Mouse' (a nil value)
I recommend you do all the server side needed things on the server side and try to keep the mouse out of the server. Do the "checks" on the client-side and also the events of the mouse on the client side.