Hey guys so I'm doing code to fire a bullet.

Basically I'm creating the bullet on the client who shot the bullets side. Then to reduce load on the server, I'm creating the bullet on the other clients so that they can see the bullets path too.

I'm not sure if it's failing because I have a remote event firing to all clients while it's inside a nOnServerEvent or if there's something else happening.

Also so you aren't confused "player" in the OnServerEvent is the player that was shot lol. I'll probably change that to make it clear for me.

Here's the code for the servers code that is firing to all clients:

-- Replicated Storage  For Shooting
local ShootEvent = game.ReplicatedStorage:WaitForChild("ShootEvent")
local ClientShootEvent = game.ReplicatedStorage:WaitForChild("ClientShootEvent")
-- Module Script
local MyFunctions = require(game.ServerScriptService.MyFunctions)

ShootEvent.OnServerEvent:Connect(function(Player, player, BulletDamage, BulletData)
	MyFunctions.DamageDealer(BulletDamage, player)
	ClientShootEvent:FireAllClients(Player, BulletData)
end)

Here is the Local script inside StarterPlayerScripts

local player = game.Players.LocalPlayer

-- Replicated Storage
local ShootEvent = game.ReplicatedStorage.ClientShootEvent

ShootEvent.OnClientEvent:Connect(function(Player, BulletData)
	print("hello\n")
	if Player == player then
		return print("hello\n")
	else
		local NewBullet = game.ReplicatedStorage.Bullets:FindFirstChild(BulletData.BulletName.Value):Clone()
		NewBullet.Position = BulletData.BulletPosition.Value
		NewBullet.Parent = game.Workspace
		NewBullet.Velocity = BulletData.BulletVelocity.Value
	end
end)

Also not sure if it would even recreate the bullet doing this but I can't test it out because the OnClient Event won't run. I put print statements inside it and nothing is being outputted.

Thank you!

Sorry for wasting time. I realized it was only running if I shot someone. I forgot about the if statement I put in the gun script.

2 comments

0

Do any errors appear, or just nothing happens?

0

Nothing Happens. No errors