Bullet holes on surfaces


  • This will put a bullet hole on a surface that you click on.

    local mouse = game.Players.LocalPlayer:GetMouse()
    mouse.Button1Down:connect(function()
    	local target = mouse.Target
    	if not target then return end
    	local face = mouse.TargetSurface.Name
    	local resolution = 100
    	local size = target.Size*resolution
    	local g = target:FindFirstChild("HoleGui"..face)
    	if not g then
    		g = Instance.new("SurfaceGui")
    		g.Face = mouse.TargetSurface
    		g.Name = "HoleGui"..face
    		if face == "Front" or face == "Back" then
    			g.CanvasSize = Vector2.new(size.X, size.Y)
    		elseif face == "Left" or face == "Right" then
    			g.CanvasSize = Vector2.new(size.Z, size.Y)
    		elseif face == "Top" or face == "Bottom" then
    			g.CanvasSize = Vector2.new(size.Z, size.X)
    		end
    		g.Parent = target
    		local f = Instance.new("Frame")
    		f.Size = UDim2.new(1, 0, 1, 0)
    		f.BackgroundTransparency = 1
    		f.ClipsDescendants = true
    		f.Parent = g
    		g = f
    	else
    		g = g.Frame
    	end
    	local relative = target.CFrame:inverse()*mouse.Hit.p
    	relative = Vector2.new(.5, .5) - ({
    		Front  = Vector2.new( relative.X,  relative.Y);
    		Back   = Vector2.new(-relative.X,  relative.Y);
    		Left   = Vector2.new(-relative.Z,  relative.Y);
    		Right  = Vector2.new( relative.Z,  relative.Y);
    		Top    = Vector2.new( relative.Z, -relative.X);
    		Bottom = Vector2.new( relative.Z,  relative.X);
    	})[face]/g.Parent.CanvasSize*resolution
    	local e = Instance.new("ImageLabel")
    	e.BackgroundTransparency = 1
    	e.Image = "rbxassetid://113742165"
    	e.Size = UDim2.new(0, resolution, 0, resolution)
    	e.Position = UDim2.new(relative.X, -resolution/2, relative.Y, -resolution/2)
    	e.Parent = g
    end)
    

    edit: demo gif
    gif


  • Great script! To tell the truth when I saw the title I thought this was a another script that just created a part where you click. But you have created something elegant.

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.