Help with spraycan

Hi

I have made a spray can system but the spray parts don’t get the orientation of the object. So spraying it on the floor works but when I spray it on a wall it’s still horizontal

Client Script:

coroutine.resume(coroutine.create(function()
	while true do

		if isPainting then

			local userInputService = game:GetService("UserInputService")

			local mouseVP = userInputService:GetMouseLocation()
			local mouseRay = workspace.CurrentCamera:ViewportPointToRay(mouseVP.x, mouseVP.y)
			local params = RaycastParams.new()
			params.FilterType = Enum.RaycastFilterType.Blacklist

			local ignoreDescendants = {workspace.SprayPaint}

			for i,v in pairs(game:GetService("Players"):GetChildren()) do

				local char = v.Character or v.CharacterAdded:Wait()

				if char then

					table.insert(ignoreDescendants, char)

				end

			end

			params.FilterDescendantsInstances = ignoreDescendants -- Put the new spray paint parts in that model so it can ignore them

			local result = workspace:Raycast(mouseRay.Origin, mouseRay.Unit.Direction * 300, params)

			if result.Instance and result.Position then

				script.Parent:WaitForChild("Paint"):FireServer(result.Position)

			end
		end

		task.wait(0.02)
	end
end))

Server script just fires an event to all clients.
The event is received in this local script:

local RS = game:GetService(“ReplicatedStorage”)

RS:WaitForChild(“SprayPaint”).OnClientEvent:Connect(function(pos)

local part = RS:WaitForChild("PaintPart"):Clone()
part.Parent = workspace.SprayPaint
part.Anchored = true
part.Position = pos
part.Size = Vector3.new(1, 0.008, 1)
part.Material = Enum.Material.SmoothPlastic

end)


Thanks

If i’m not wrong, your issue probably is because you only copying and pasting the position where the raycast detected a object. so in order to make the spray parts rotate correctly on the floor, you can use

replace

script.Parent:WaitForChild("Paint"):FireServer(result.Position,result.Normal)

for

script.Parent:WaitForChild("Paint"):FireServer(result.Position)

in your client script

and here’s how to make that the part

replace this with your entire server script :

local RS = game:GetService(“ReplicatedStorage”)

RS:WaitForChild(“SprayPaint”).OnClientEvent:Connect(function(plr,pos,normal)

local part = RS:WaitForChild("PaintPart"):Clone()
part.Parent = workspace.SprayPaint
part.Anchored = true
part.Position = pos
part.CFrame = CFrame.new(part.Position, normal + pos)
part.Size = Vector3.new(1, 0.008, 1)
part.Material = Enum.Material.SmoothPlastic
end)

This hopefully would work for you in the first try, but if there’s something went wrong, feel free to tell me

you didn’t do strings correctly

replace this “” with ""

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.