Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved]How come the BulletHoles keep facing one direction?

Asked by 2 years ago
Edited 2 years ago

I'm currently working on custom bulletholes, but whenever I test it the part is only facing forward it never faces the intended direction. I don't know exactly why this is happening. I've looked at every question on the site involving bulletholes only one has helped me so far but it is the main cause of my problem. I don't really understand how cframes work and they have always given me a headache to work with. Can somebody please help me?

Script

Evt.HitEffect.OnServerEvent:Connect(function(Player, Position, HitPart, Normal, Material, Settings)
    if HitPart.Parent:FindFirstChild("Humanoid") then
        print("Player Hit.")
    else        
        local BulletPart = Instance.new("Part", HitPart)
        BulletPart.Name = "BulletHole"
        BulletPart.Transparency = 1
        BulletPart.CanCollide = false
        BulletPart.Size = Vector3.new(0.1, .5, .5)
        BulletPart.CFrame = CFrame.new(Position)*CFrame.Angles(math.rad(Normal.X),math.rad(Normal.Y),math.rad(Normal.Z))*CFrame.Angles(0,math.rad(180),0) -- line in question

        local BulletImage = Instance.new("Decal", BulletPart)
        BulletImage.Texture = "rbxassetid://114148608"
        BulletImage.Face = Enum.NormalId.Left

        local BulletWeld = Instance.new("WeldConstraint", BulletPart)
        BulletWeld.Name = "BulletWeld"
        BulletWeld.Part0 = BulletPart
        BulletWeld.Part1 = HitPart

        game.Debris:AddItem(BulletPart, math.huge)
    end
    Evt.HitEffect:FireAllClients(Player, Position, HitPart, Normal, Material, Settings)
end)

If you would like to resolve this over discord

My Discord user is "VincenttheBaguette1#1253"

1 answer

Log in to vote
0
Answered by 2 years ago

I was able to fix the issue with the help of TheEvilDucks Tutorial. I'll explain what I did. First I went to the script that fires the event and I get the mouses position. I'll show an example on how to do that.

This is an Example! I didn't test it.

local plr = game.Players.LocalPlayer --plr is the player
local ReplicatedStorage = game.ReplicatedStorage
local MouseHit = plr:GetMouse().Hit --mouse’s position in 3D space

ReplicatedStorage.ExampleEvent:FireServer(MouseHit.Position) --this will send the exact position of the mouse.

I use then give the BulletPart the mouse position. Then the way I make sure the image is seen on every face I change cframe to BulletPart.CFrame = CFrame.new(Position, Position + Normal). The complete script will be put below.

Evt.HitEffect.OnServerEvent:Connect(function(Player, Position, HitPart, Normal, Material, Settings, MouseHit)
    if HitPart.Parent:FindFirstChild("Humanoid") then
        print("Player Hit.")
    else        
        print(math.floor(MouseHit.X)..","..math.floor(MouseHit.Y)..","..math.floor(MouseHit.Z)) --No point in this line I just put it there for testing.
        local BulletPart = Instance.new("Part", HitPart)
        BulletPart.Name = "BulletHole"
        BulletPart.Transparency = 1
        BulletPart.CanCollide = false
        BulletPart.Size = Vector3.new(0.5, .5, .1) --I switched z's size for x's vice versa
        BulletPart.Position = MouseHit --I set the position to the mouse's
        BulletPart.CFrame = CFrame.new(Position, Position + Normal) --you can see the line from above here

        local BulletImage = Instance.new("Decal", BulletPart)
        BulletImage.Texture = "rbxassetid://114148608"
        BulletImage.Face = Enum.NormalId.Front --you can see I changed the NormalId to Front.

        local BulletWeld = Instance.new("WeldConstraint", BulletPart)
        BulletWeld.Name = "BulletWeld"
        BulletWeld.Part0 = BulletPart
        BulletWeld.Part1 = HitPart

        game.Debris:AddItem(BulletPart, 7)
    end
    Evt.HitEffect:FireAllClients(Player, Position, HitPart, Normal, Material, Settings)
end)

It's not as professional as I want but it gets the work done.

Ad

Answer this question