local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local char = plr.Character or plr.CharacterAdded:wait() local fireball = game.ReplicatedStorage.FireBending.Fire1 local canattack = true local checkdeath = true mouse.KeyDown:connect(function(key) if key == "z" and canattack == true then canattack = false local fire = fireball:Clone() fire.Parent = workspace fire.CFrame = char.Humanoid.Torso.CFrame * CFrame.new(0,0,-10) local bodyv = Instance.new("BodyVelocity") bodyv.MaxForce = Vector3.new(1e8,1e8,1e8) bodyv.Velocity = char.Humanoid.Torso.CFrame.lookVector * 150 bodyv.Parent = fire local fireanim1 = char.Humanoid:LoadAnimation(script.FireAnim1) local fireanim2 = char.Humanoid:LoadAnimation(script.FireAnim2) local fireanim3 = char.Humanoid:LoadAnimation(script.FireAnim3) local choose = math.random(1,3) if choose == 1 then fireanim1:Play() elseif choose == 2 then fireanim2:Play() elseif choose == 3 then fireanim3:Play() end wait(2) fire:remove() wait(1) canattack = true end end) while checkdeath == true do wait(.1) if plr.Character.Humanoid.Health <= 0 then script:remove() end end
The code at the top is the local script for my fireball and seems to work just fine Its just that whenever I hop in my game to test with my friend he can't see the fireball and I can't see his Does anyone know how to fix? (Animations work just fine)
The reason it shows up to you only is that it's on the client, not on the server. You'll need to use RemoteEvents
and fire it upon the MouseKeyDown function. Add a RemoteEvent
in ReplciatedStorage and copy what I do.
Local script:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local char = plr.Character or plr.CharacterAdded:wait() local fireball = game.ReplicatedStorage.FireBending.Fire1 local canattack = true local checkdeath = true mouse.KeyDown:connect(function(key) if key == "z" and canattack == true then game.ReplicatedStorage.RemoteEvent:FireServer() -- Fires the RemoteEvent end end)
Now, add a script into ServerScriptService
:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) local mouse = plr:GetMouse() local char = plr.Character or plr.CharacterAdded:wait() local fireball = game.ReplicatedStorage.FireBending.Fire1 local canattack = true local checkdeath = true canattack = false local fire = fireball:Clone() fire.Parent = workspace fire.CFrame = char.Humanoid.Torso.CFrame * CFrame.new(0,0,-10) local bodyv = Instance.new("BodyVelocity") bodyv.MaxForce = Vector3.new(1e8,1e8,1e8) bodyv.Velocity = char.Humanoid.Torso.CFrame.lookVector * 150 bodyv.Parent = fire local fireanim1 = char.Humanoid:LoadAnimation(script.FireAnim1) local fireanim2 = char.Humanoid:LoadAnimation(script.FireAnim2) local fireanim3 = char.Humanoid:LoadAnimation(script.FireAnim3) local choose = math.random(1,3) if choose == 1 then fireanim1:Play() elseif choose == 2 then fireanim2:Play() elseif choose == 3 then fireanim3:Play() end wait(2) fire:remove() wait(1) canattack = true end end) while checkdeath == true do wait(.1) if plr.Character.Humanoid.Health <= 0 then script:remove() end end