Hello. I’m making a spray tool that lets you spray decals on walls, but it doesn’t work as expected. I want it to spray decals on every surface, and properly. Currently, I am using ray-casting to achieve this. Thank you for any help, I really appreciate it. Thank you, again.
Please help if you can
Here’s my code:
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local wallDetector = script.Parent:WaitForChild("WallDetector")
local sprayPaint = script.Parent
local function ray_Cast(a, b, params, debugMode)
local rayResult = game:GetService("Workspace"):Raycast(a, b, params)
if (rayResult) then
return rayResult
else
return nil;
end
end
sprayPaint.Activated:Connect(function()
local params = RaycastParams.new();
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {player.Character, sprayPaint}
local a = wallDetector.Position;
local b = wallDetector.Position + (wallDetector.CFrame.LookVector * 0.1);
local result = ray_Cast(a, b, params, true)
if not (result) then return end
local decal = game:GetService("ReplicatedStorage").Decal:Clone();
local decalPart = Instance.new("Part");
decal.Parent = decalPart
decal.Face = Enum.NormalId.Front
decalPart.Anchored = true
decalPart.CanCollide = false
decalPart.Size = Vector3.new(1, 1, 1)
decalPart.CFrame = CFrame.new(result.Position + (decalPart.Size/2))
decalPart.Parent = workspace
decalPart.Transparency = 1;
decalPart.Parent = workspace
end)
Regards,
ChainsawRBLX