Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

OnClientEvent can only be used on the client, how do I fix this error?

I recently started scripting and I decided to try to make a fireball(tool) that launches when I click,

This local script is in StarterPack, it's the tool's child:

local tool = script.Parent
local remote = game:GetService("ReplicatedStorage"):WaitForChild("FireballTool")
tool.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        remote:FireServer()
    end)
end)

and this script is in ServerScriptService:

Player = game.Players.LocalPlayer

local remote = game:GetService("ReplicatedStorage"):WaitForChild("FireballTool")
remote.OnClientEvent:Connect(function(Player)
    local fireball = Instance.new("Part")
   
fireball.BrickColor = BrickColor.new("Maroon")
fireball.Transparency = 0.4
fireball.Shape = "Ball"
fireball.TopSurface = "Smooth"
fireball.BottomSurface = "Smooth"
fireball.CanCollide = false 
 fireball.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new (2,1,9)
local bv = Instance.new("BodyVelocity",fireball)
			bv.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 85
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

    fireball.Parent = workspace
wait(2)
fireball:remove()


end)

(yes, I put a remote event called FireballTool in ReplicatedStorage) I don't know what I did wrong and why the error " OnClientEvent can only be used on the client" shows up, please help?

1 comment

0

On line 3, instead of "OnClientEvent" it should say "OnServerEvent"

1 answer

Instead of using OnClientEvent, try using OnServerEvent.

This discussion is preserved as it was. New answers, comments, and votes are closed.