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

My bullet stays in same place how to fix? (lerping)

Asked by
ym5a 52
3 years ago
local debris = game:GetService("Debris")

--This is the Server Script
local function shootbullet(origin,direction,ting)   
    local part = Instance.new("Part")
    part.Parent = game.Workspace.Laseronias
    part.Material = Enum.Material.Plastic
    part.BrickColor = BrickColor.new("Gold")
    part.Size = Vector3.new(0.1,0.1,0.1)
    part.Anchored = true
    part.CanCollide = false
    part.Position = origin.Position
    for i = 0,1,0.1 do
        wait()
        part.Position:Lerp(ting,i)
        print("moved")
        print(ting)
    end
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,jP,oP)
    local DEST = (jP-oP.Position).Unit * 999
    local tikn = (jP-oP.Position)
    local Res = workspace:Raycast(oP.Position,DEST)
    local resPart = Res.Instance
    if Res then
        print(Res.Instance.Name)
        if resPart.Parent:FindFirstChild("Humanoid") and resPart.Parent:FindFirstChild("Humanoid") ~= player.Character:FindFirstChild("Humanoid") then
            resPart.Parent:FindFirstChild("Humanoid"):TakeDamage(100)
        end
    end
    shootbullet(oP,DEST,tikn)
end)


--This is the Localscript
local Jerry = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local origin = script.Parent.meGun.Origins
local debounce = false
local cooldown = 0.2
Jerry.TargetFilter = game.Workspace.Laseronias
Jerry.TargetFilter = origin
script.Parent.Activated:Connect(function()
    if debounce then return end
    debounce = true
    local jerryPos = Jerry.hit.p
    local oPos = origin

    game.ReplicatedStorage.RemoteEvent:FireServer(jerryPos,oPos)
    wait(cooldown)
    debounce = false
end)

So it prints my correct position of the mouse and "moved" but it just doesnt move and stays at the origin position how i fix it ? !

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
3 years ago

Hello, ym5a!

You forgot to actually set the bullet position to the lerped position:

I also had to make some changes to make so the bullet will move at the same velocity every time

(SERVER SCRIPT)

local debris = game:GetService("Debris")

--This is the Server Script
local function shootbullet(origin,direction,ting)   
    local part = Instance.new("Part")
    part.Parent = game.Workspace.Laseronias
    part.Material = Enum.Material.Plastic
    part.BrickColor = BrickColor.new("Gold")
    part.Size = Vector3.new(0.1,0.1,0.1)
    part.Anchored = true
    part.CanCollide = false
    part.Position = origin.Position
    local startPos = part.Position
    for i = 0,1,0.1 do
        wait()
        part.Position = startPos:Lerp(ting,i)
        print("moved")
        print(ting)
    end
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,jP,oP)
    local DEST = (jP-oP.Position).Unit * 999
    local tikn = (jP-oP.Position)
    local Res = workspace:Raycast(oP.Position,DEST)
    local resPart = Res.Instance
    if Res then
        print(Res.Instance.Name)
        if resPart.Parent:FindFirstChild("Humanoid") and resPart.Parent:FindFirstChild("Humanoid") ~= player.Character:FindFirstChild("Humanoid") then
            resPart.Parent:FindFirstChild("Humanoid"):TakeDamage(100)
        end
    end
    shootbullet(oP,DEST,tikn)
end)



If this answers your question, please don't forget to mark this as the Accepted Answer, it helps a lot

0
So, it kind of worked (it moves) but it doesnt always go where the mouse is. ym5a 52 — 3y
0
That part is controlled in the local script, but its not the point of your question, and I really have no clue what is wrong Leamir 3138 — 3y
Ad

Answer this question