I want to fire a remote event from a local script, if I fire it nothing happens, why not?

Script (in serverscriptservice, localscript)

local dam
local Rep = game:GetService("ReplicatedStorage")
local event = Rep.ChopTree

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local cliks = 0
local cooldown = 1.2

local animaton = script.Parent.Animation
local work = humanoid:LoadAnimation(animaton)
local Tool = script.Parent

local animaton2 = script.Parent.AxeChopping
local work2 = humanoid:LoadAnimation(animaton2)

local target

event.OnServerEvent:Connect(function(mouse)
		work2:Play()
		work2:AdjustSpeed(1.4)
		target = mouse.Target
		if target.Parent.Name == "Tree" then
		target.Parent.damage.Value = target.Parent.damage.Value - 5
			game.Players.LocalPlayer.PlayerGui.HitObjectUI.Health.Visible = true
			game.Players.LocalPlayer.PlayerGui.HitObjectUI.Health.ObjectName.Text = target.Parent.Name
			dam = target.Parent.damage.Value
			game.Players.LocalPlayer.PlayerGui.HitObjectUI.Health.TextLabel.Text = ("HP: ".. dam.."/25")
		if target.Parent.damage.Value == 0 then
			target.Parent:Destroy()
			game.Players.LocalPlayer.PlayerGui.HitObjectUI.Health.Visible = false
			game.Players.LocalPlayer.PlayerGui.HitObjectUI.Health.TextLabel.Text = "HP: 25/25"
		end
		end
	end)

I used a local script to use LocalPlayer

3 comments

0

Are you firing the remote event to the server via event:FireServer()? If so, the above script has to be a server script.

0

LocalScripts don't work in ServerScriptService. LocalScripts don't even see ServerScriptService. Also, LocalScript's cannot use OnServerEvent, that's an event for server-side listening. Look up what LocalScripts and Server-Scripts can do

0

A local script in ServerScriptService???