no idea how to solve this and i cant find anyone with similar issues on devforum.
serverscript:
local tool = script.Parent
local soundEvent = tool.RemoteEvents.PlaySound
local throwEvent = tool.RemoteEvents.ThrowGrenade
local function isPlayerValid(player)
local character = player.Character
local head = player.Character:FindFirstChild("Head")
local humanoid = player.Character:FindFirstChild("Humanoid")
return character and head and humanoid and humanoid.Health > 0
end
soundEvent.OnServerEvent:Connect(function(player, sound)
if not isPlayerValid(player) then return end
if tool.Handle.Sounds:IsAncestorOf(sound) and sound:IsA("Sound") then
sound:Play()
end
end)
--FASTCAST[
local fastCast = require(game.ReplicatedStorage.FastCastRedux)
fastCast.VisualizeCasts = true
local caster = fastCast.new()
local castParams = RaycastParams.new()
castParams.FilterDescendantsInstances = {tool.Parent}
castParams.FilterType = Enum.RaycastFilterType.Exclude
local behavior = fastCast.newBehavior()
behavior.RaycastParams = castParams
behavior.MaxDistance = tool.Values.MaxDistance.Value
behavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
behavior.CosmeticBulletTemplate = game.ServerStorage.BulletTemplates[tool.Name].Grenade
behavior.CosmeticBulletContainer = workspace.Projectiles
--FASTCAST]
throwEvent.OnServerEvent:Connect(function(player, mouse)
if not isPlayerValid(player) then return end
local head = player.Character.Head
local speed = tool.Values.StudsPerSecond.Value
local grenadeOrigin = head.Position + Vector3.new(0, 1, 0)
local direction = (mouse - grenadeOrigin).Unit * 300
caster:Fire(grenadeOrigin, direction, speed, behavior)
end)
caster.LengthChanged:Connect(function(cast, lastPoint, direction, length, velocity, grenade)
if grenade then
local grenadeLength = grenade.Size.Z/2
local offset = CFrame.new(0, 0, -(length - grenadeLength))
grenade.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end)