I have a bullet effect firing on the client, trying to replicate it to the rest of the clients. Logic behind the script follows this post:
Event doesn’t seem to be firing from Server - Client in order to replicate.
LOCAL SCRIPT
local function Bullet(user)
local mouse = player:GetMouse()
local proj = Instance.new("Part")
local force = Instance.new("LinearVelocity")
local Attachment0 = Instance.new("Attachment")
Attachment0.Parent = proj
proj.Parent = game.Workspace
proj.Position = script.Parent.Part.Position
force.Parent = proj
force.Attachment0 = Attachment0
force.VectorVelocity = (mouse.Hit.Position - proj.Position).Unit * 5
proj.CFrame = CFrame.lookAt(script.Parent.Part.Position, mouse.Hit.Position)
proj.CanCollide = false
proj.Color = Color3.new(1, 1, 0)
proj.Anchored = false
proj.Material = "Neon"
proj.Size = Vector3.new(0.05, 0.05, 1.5)
wait(10)
proj:Destroy()
end
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
pistolFire:FireServer()
Bullet(player)
end
end)
pistolFire.OnClientEvent:Connect(function()
print("hello")
end)
SERVER SCRIPT
local pistolFire = script.Parent:WaitForChild("pistolFire")
local function bounceRemote(player, user)
for i,v in ipairs(game.Players:GetPlayers()) do --getting all the players in the game
if v ~= player then --all players BUT the one who blew it, (they already ran it on the client in the earlier code at blowBubble(player) after BlowEvent:FireServer()
user = v
print(player, user)
pistolFire:FireClient(v, player)
end
end
end
pistolFire.OnServerEvent:Connect(bounceRemote)
--- Client ---
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local pistolFire = script.Parent:WaitForChild("pistolFire")
-- Make sure pistolFire is a RemoteEvent located in ReplicatedStorage.
local function Bullet()
local mouse = LocalPlayer:GetMouse()
local proj = Instance.new("Part")
local force = Instance.new("LinearVelocity")
local Attachment0 = Instance.new("Attachment")
Attachment0.Parent = proj
proj.Parent = game.Workspace
proj.Position = script.Parent.Part.Position
force.Parent = proj
force.Attachment0 = Attachment0
force.VectorVelocity = (mouse.Hit.Position - proj.Position).Unit * 5
proj.CFrame = CFrame.lookAt(script.Parent.Part.Position, mouse.Hit.Position)
proj.CanCollide = false
proj.Color = Color3.new(1, 1, 0)
proj.Anchored = false
proj.Material = "Neon"
proj.Size = Vector3.new(0.05, 0.05, 1.5)
task.delay(10, function()
proj:Destroy()
end)
end
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
pistolFire:FireServer()
Bullet()
end
end)
pistolFire.OnClientEvent:Connect(function()
print("Fired")
end)
--- Server ---
local Players = game:GetService("Players")
local pistolFire = script.Parent:WaitForChild("pistolFire")
local function bounceRemote(player)
for _, other in Players:GetPlayers() do
if other ~= player then
pistolFire:FireClient(other)
end
end
end
pistolFire.OnServerEvent:Connect(bounceRemote)
ah, wait, hold on. i dont know if this solves your issue, just comment back.
local UIS = game:GetService("UserInputService")
local pistolFire = game:GetService("ReplicatedStorage"):WaitForChild("pistolFire")
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
pistolFire:FireServer()
end
end)
pistolFire.OnClientEvent:Connect(function(msg)
warn(msg)
end)
Server script:
local pistolFire = game:GetService("ReplicatedStorage"):WaitForChild("pistolFire")
pistolFire.OnServerEvent:Connect(function(player)
for _, p in pairs(game.Players:GetPlayers()) do
if p ~= player then
pistolFire:FireClient(p, "from different client")
else
pistolFire:FireClient(p, "from same client")
end
end
end)
If this simplified version doesnt work in your game, then theres a different issue