I have a fireball local script in starter character scripts that lets the user charge up a fireball and then shoot it at other players. They can also click to teleport to the fireball - that’s how they move around
I have a problem though when i start a local server to test, it works fine, the fireball damages the other player but when I switch to that player’s screen they’re still up and standing and I can still move them around
but when i go back to the other screen the character is dead
This is my script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local debounce = false
local ball
local force -- define force here
local maxSize = 6 -- maximum size of the ball
local chargeRate = 0.1 -- rate at which the ball grows
local normalJumpPower = 50 -- normal jump power
local gravity = Vector3.new(0, workspace.Gravity, 0) -- gravity in the workspace
-- function to create the ball
local function createBall()
local part = Instance.new("Part")
part.Material = "Neon"
part.Color = Color3.new(0.572549, 0.905882, 1)
part.Size = Vector3.new(1,1,1)
part.Position = Vector3.new(player.Character.HumanoidRootPart.Position.X,player.Character.HumanoidRootPart.Position.Y + 5 ,player.Character.HumanoidRootPart.Position.Z)
part.Parent = game.Workspace
local mesh = Instance.new("SpecialMesh", part)
mesh.MeshType = Enum.MeshType.Sphere
-- create a BodyForce to counteract gravity
force = Instance.new("BodyForce")
force.Force = gravity * part:GetMass()
force.Parent = part
-- create a Touched event to damage other players and handle ball collisions
part.Touched:Connect(function(hit)
local otherPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if otherPlayer then
otherPlayer.Character.Humanoid.Health = otherPlayer.Character.Humanoid.Health - 10 -- adjust damage as needed
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
local particleEmitter = Instance.new("ParticleEmitter")
particleEmitter.Parent = explosion
wait(0.5) -- particles only show for half a second
particleEmitter:Destroy()
part:Destroy()
elseif hit:IsA("Part") and hit.Size == Vector3.new(1,1,1) then
hit:Destroy()
part:Destroy()
end
local function onTouched(hit2)
if hit.Parent ~= nil then
local human = hit.Parent:FindFirstChildOfClass("Humanoid")
if human then
if debounce == false then
debounce = true
human.Health -= 24
wait(3)
debounce = false
end
end
end
end
onTouched()
--script.Parent.Touched:Connect(onTouched)
end)
return part
end
-- function to handle mouse button down
local function mouseDown()
if debounce then
local oldPosition = player.Character.HumanoidRootPart.Position
player.Character:SetPrimaryPartCFrame(CFrame.new(ball.Position))
ball:Destroy()
debounce = false
player.Character.Humanoid.JumpPower = normalJumpPower
player.Character.Humanoid.PlatformStand = false
-- create a beam between the old position and the new position
local beamPart = Instance.new("Part")
beamPart.Anchored = true
beamPart.CanCollide = false
beamPart.Size = Vector3.new(0.3, 0.2, (ball.Position - oldPosition).Magnitude)
beamPart.CFrame = CFrame.new((ball.Position + oldPosition) / 2, oldPosition)
beamPart.BrickColor = BrickColor.new("Bright yellow")
beamPart.Parent = game.Workspace
beamPart.Material = "Neon"
wait(0.12) -- beam shows for a tenth of a second
beamPart:Destroy()
local particleEmitter = Instance.new("ParticleEmitter")
particleEmitter.Parent = player.Character.HumanoidRootPart
wait(0.5) -- particles only show for half a second
particleEmitter:Destroy()
else
debounce = true
ball = createBall()
player.Character.Humanoid.JumpPower = 0 -- player can't jump
player.Character.Humanoid.PlatformStand = true
while mouse.Button1Down and ball.Size.X < maxSize do
ball.Size = ball.Size + Vector3.new(chargeRate, chargeRate, chargeRate)
force.Force = gravity * ball:GetMass() -- update the force to counteract gravity
wait()
end
end
end
-- function to handle mouse button up
local function mouseUp()
if not debounce or not ball then return end
local direction = (mouse.Hit.p - player.Character.HumanoidRootPart.Position).unit
ball.CFrame = CFrame.new(ball.Position, mouse.Hit.p) -- set the direction of the ball using CFrame
ball.Velocity = direction * 100
player.Character.Humanoid.JumpPower = normalJumpPower
player.Character.Humanoid.PlatformStand = false
end
mouse.Button1Down:Connect(mouseDown)
mouse.Button1Up:Connect(mouseUp)
I’m not sure what I’m doing wrong can someone please help me I think its something about it being only client sided but i don’t know how to make it serversided