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!
Use mouse.Move instead of while true do
Local
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, Mouse) else print("Cant do that") end end end)
Server
local Paint = game.ReplicatedStorage.Paint ButtonPressed = false Paint.OnServerInvoke = function(player, MousePos, ButtonPressed, Mouse) local Folder = Instance.new("Folder", game.Workspace) ButtonPressed = true Folder.Name = "Parts" wait() Mouse.Move:Connect(function() if ButtonPressed == true then 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) end