So I have been working on a game in which you throw a snowball which includes drop. Now the thing is is that it works completely fine normally, but it drops way slower if I am moving to the left or backwards. I have absolutely no idea how to fix this so I would appreciate ideas or comments. Thanks!
Looks like it seems to work fine if you’re not moving, could we see le script that handles the snowball throwing?
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local RS = game:GetService("ReplicatedStorage")
local event = RS.Events:WaitForChild("SBThrow")
local UIS = game:GetService("UserInputService")
local debounce = false
local sound = RS.Sounds:WaitForChild("Throw")
local int = char:WaitForChild("Ammo")
local mouse = player:GetMouse()
local anim = RS.Animations:WaitForChild("Throw")
local animtrack = hum:LoadAnimation(anim)
UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then
return
elseif input.UserInputType == Enum.UserInputType.MouseButton1 and int.Value >= 1 and
char.HumanoidRootPart.Anchored == false and debounce == false then
int.Value = int.Value - 1
sound:Play()
event:FireServer(mouse.Hit)
animtrack:Play()
debounce = true
end
end)
event.OnClientEvent:Connect(function()
wait(0.5)
debounce = false
end)```
May we see the RemoteEvent you havem, aka the OnServerEvent code for SBThrow
do you mean the localscript? or where its located
The code for the OnServerEvent
of SBThrow
in a regular script since we can’t go off of the localscript
local RS = game:GetService("ReplicatedStorage")
local event = RS.Events:WaitForChild("SBThrow")
local UIS = game:GetService("UserInputService")
local snow = RS.Meshes:WaitForChild("Snowball")
local TweenService = game:GetService("TweenService")
local damage = 37
local debris = game:GetService("Debris")
local HitSound = RS.Sounds.Hit
event.OnServerEvent:Connect(function(player,md)
local Snowball = snow:Clone()
Snowball.CFrame = player.Character.RightHand.CFrame
Snowball.CanCollide = false
Snowball.Anchored = false
Snowball.Parent = workspace
local hitbox = Instance.new("Part")
hitbox.Size = Vector3.new(3,3,3)
hitbox.Anchored = false
hitbox.Transparency = 1
hitbox.CFrame = Snowball.CFrame
hitbox.Parent = workspace
hitbox.CanCollide = false
hitbox.Massless = true
local weld = Instance.new("ManualWeld")
weld.Part0 = hitbox
weld.Part1 = Snowball
weld.Parent = weld.Part0
local char = player.Character
local humrp = char.HumanoidRootPart
Snowball:SetNetworkOwner(player)
local velocity = Instance.new("BodyVelocity",Snowball)
velocity.MaxForce = Vector3.new(1,1,1) * math.huge
velocity.Velocity = md.LookVector * 150
Snowball.Parent = workspace
debris:AddItem(Snowball,5)
hitbox.Touched:Connect(function(hit)
local hitSFX = Instance.new("Sound",Snowball); hitSFX.SoundId = "rbxassetid://4518881974"
if hit:IsA("BasePart") then
if not hit:IsDescendantOf(char) then
local Ehum = hit.Parent:FindFirstChild("Humanoid")
if Ehum then
Ehum:TakeDamage(damage)
hitSFX:Play()
hitbox:Destroy()
wait()
Snowball:Destroy()
end
end
end
wait(0.1)
spawn(function()
while wait(0.1) do
velocity.Velocity = velocity.Velocity - Vector3.new(0,1,0)
end
end)
end)
event:FireClient(player)
end)
lol i didnt realize i sent the localscript
Not sure how much it’ll help, but maybe you can use Unitray.Direction
instead of Hit
?
event:FireServer(mouse.UnitRay.Direction)
And in the OnServerEvent
velocity.Velocity = md * 150
UnitRay is jsut a 1 stud long Ray that is directed towards mouse.Hit, maybe you can use that instead?
It does work just as well, but unfortunately, it still goes straight when I move left.
you should put some server side checks or exploiters might use a script like this to spam snowballs
Potential Exploit
local plr = game.Players.LocalPlayer
local rs = game:GetService("RunService")
local event = game.ReplicatedStorage.Events.SBThrow
local mouse = plr:GetMouse()
local firing = false
mouse.Button1Down:Connect(function()
firing = true
end)
mouse.Button1Up:Connect(function()
firing = false
end)
while rs.Heartbeat:Wait() do
if firing == true then
event:FireServer(mouse.Hit)
end
end
Although I would agree, this is unrelated to the OP
Could you try using Mouse.Hit.Position
?
I’ve tried all of them but I have no idea why this is happening
Your bullet drop function is inside the touched function for some reason
Heres what I imagine is happening:
- When you are moving forwards the touch event is fired because it touches the player, as it is a stationary and easy to hit target
- When you are strafing side to side, the snowball lags behind and consequently does not activate the bullet drop section of the script
Id reccomend moving the bullet drop section to after the event exits then reexamining what happens
i didnt notice that, fixing rn
tysm, it is a little wonky but changing it fixed it completely. I appreciate the help!