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:
01 | Player = game.Players.LocalPlayer |
02 | Mouse = Player:GetMouse() |
03 | local Paint = game.ReplicatedStorage.Paint |
04 |
05 | Mouse.Button 1 Down:connect( function () |
06 | local MousePos = Mouse.Hit.p |
07 | local MouseA = Mouse |
08 | if Mouse.Target ~ = nil then |
09 | if Mouse.Target.Name = = "Canvas" and "ColorPart" then |
10 | Paint:InvokeServer(MousePos, MouseA) |
11 | else |
12 | print ( "Cant do that" ) |
13 | end |
14 | end |
15 | end ) |
ServerScript:
01 | local Paint = game.ReplicatedStorage.Paint |
02 | ButtonPressed = false |
03 |
04 | Paint.OnServerInvoke = function (player, MousePos, ButtonPressed) |
05 | local Folder = Instance.new( "Folder" , game.Workspace) |
06 | ButtonPressed = true |
07 | Folder.Name = "Parts" |
08 | wait() |
09 | if ButtonPressed = = true then |
10 | while true do |
11 | wait() |
12 | local Part = Instance.new( "Part" , game.Workspace.Parts) |
13 | Part.Name = "ColorPart" |
14 | Part.Position = MousePos |
15 | Part.Size = Vector 3. new( 1.04 , 1 , 0.05 ) |
If somebody could help me with my problem that would be great! Thanks!
Use mouse.Move instead of while true do
Local
01 | Player = game.Players.LocalPlayer |
02 | Mouse = Player:GetMouse() |
03 | local Paint = game.ReplicatedStorage.Paint |
04 |
05 | Mouse.Button 1 Down:connect( function () |
06 | local MousePos = Mouse.Hit.p |
07 | local MouseA = Mouse |
08 | if Mouse.Target ~ = nil then |
09 | if Mouse.Target.Name = = "Canvas" and "ColorPart" then |
10 | Paint:InvokeServer(MousePos, MouseA, Mouse) |
11 | else |
12 | print ( "Cant do that" ) |
13 | end |
14 | end |
15 | end ) |
Server
01 | local Paint = game.ReplicatedStorage.Paint |
02 | ButtonPressed = false |
03 |
04 | Paint.OnServerInvoke = function (player, MousePos, ButtonPressed, Mouse) |
05 | local Folder = Instance.new( "Folder" , game.Workspace) |
06 | ButtonPressed = true |
07 | Folder.Name = "Parts" |
08 | wait() |
09 | Mouse.Move:Connect( function () |
10 | if ButtonPressed = = true then |
11 | wait() |
12 | local Part = Instance.new( "Part" , game.Workspace.Parts) |
13 | Part.Name = "ColorPart" |
14 | Part.Position = MousePos |
15 | Part.Size = Vector 3. new( 1.04 , 1 , 0.05 ) |