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

What's causing the delay after I fire a weapon?

Asked by
memere 22
5 years ago

Whenever I fire my weapon, the block comes up, and then there is like a .2 second delay before the velocity kicks in.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,tool,handle,mouseHit)
    local l = Instance.new("Part",workspace)
    l.BrickColor = BrickColor.new("Toothpaste")
    l.Size = Vector3.new(1,1,3)
    l.CanCollide = false
    l.Anchored = false
    l.CFrame = handle.CFrame
    l.CFrame = CFrame.new(l.Position,mouseHit.p)
    local v = Instance.new("BodyVelocity",l)
    v.Velocity = l.CFrame.lookVector * 100
    v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
end)

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You don't want to use the second parameter of Instance.new() because it takes longer.

You want to first set the properties and then parent it.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,tool,handle,mouseHit)
    local l = Instance.new("Part")
    l.BrickColor = BrickColor.new("Toothpaste")
    l.Size = Vector3.new(1,1,3)
    l.CanCollide = false
    l.Anchored = false
    l.CFrame = handle.CFrame
    l.CFrame = CFrame.new(l.Position,mouseHit.p)
    local v = Instance.new("BodyVelocity")
    v.Velocity = l.CFrame.lookVector * 100
    v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    v.Parent=l
    l.Parent=workspace
end)

I mean just look at this pic, noticeable difference.

0
Edit: Changed L to I DanzLua 2879 — 5y
0
Thanks for the advice but there is still a delay. memere 22 — 5y
0
@memere If this the result of firing to the server, there's going to be a delay regardless of what you do. That's simply the nature of these connections. You could create it locally for the client firing and then recreate them on the other clients since we want that first client to have responsiveness. (which is how most people do it) DanzLua 2879 — 5y
0
You don't have to have it make a new part every time. Just create a part in Server Storage with set properties (like size, anchored, cancollide, etc..) and have the script simply create a clone of the part in ServerStorage, and set it's parent to workspace or whatever. RuskiKrolik 34 — 5y
View all comments (13 more)
0
@RuskiKrolik Still won't make a such a difference time wise DanzLua 2879 — 5y
0
Alright thanks. memere 22 — 5y
0
I just experimented client vs server and yes, danz, you are right. The client and the server have a huge time delay. How can I recreate this is everyone's client? memere 22 — 5y
0
@memere so basically, on the client you would create the ball exactly when they click so they see it first, then you send info about it, pos and dir to server, the server will then send that stuff out to the rest of the client to reproduce. On the original client it will do the touch checks and send info to the server so it can verify its legit there. DanzLua 2879 — 5y
0
How can I make it so the server can see the second bullet but not the client? memere 22 — 5y
0
@memere You don't, the bullet only exists on the clients. DanzLua 2879 — 5y
0
How would I replicate the bullet on the other clients then? memere 22 — 5y
0
@memere You send infomation about it, through the server, such as where it originates, where it should go, etc. DanzLua 2879 — 5y
0
Wouldn't that just create a second bullet from the first client's perspective if you run it again on the server? memere 22 — 5y
0
@memere Your not creating the bullet on the server, your sending the data through the server to the OTHER clients so they can create it. Why would a another player need the server to create a bullet if that player is on the other side of the map DanzLua 2879 — 5y
0
May you refer me to a source that would explain to me how to send information from the server to every nearby client (and run it on their clients)? I would appreciate it, thank you. memere 22 — 5y
0
@memere No sources come to mind, if you understand how to fire remoteevent simply fire to the server, and there loop through each player and see if they are close enough to the player to fire the info to them. DanzLua 2879 — 5y
0
Thanks. memere 22 — 5y
Ad

Answer this question