Hi, so I’ve been debugging an axe script that is meant to cut trees down. It works on the client’s side and the client can see the tree falling down but it doesn’t show up for other players. I attempted to use a remote event to fix this, but it doesn’t work.
Everything, down to the local script and tool works well, and I know the remote event is firing but it doesn’t run on the server side for some reason. I tried to work with bool values as well but it still isn’t working.
LOCAL SCRIPT
wait(1)
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Character = game.Players.LocalPlayer.Character
Mouse.Icon = "rbxasset://textures\\GunCursor.png"
local tool = script.Parent
local function StartGui()
local NewGui = game.ReplicatedStorage.GUIs.ToolGUIs:WaitForChild("Axe"):Clone()
NewGui.Name = "Axe1"
NewGui.Parent = player.PlayerGui
print("gui cloned success")
end
local function StopGui()
local gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Axe1")
print("found axe")
if gui then
gui:Destroy()
end
end
local function onClick()
if Mouse.Target.Parent:IsA("Model") and Mouse.Target.Parent.Name == "Tree" then
print("character")
local LogPos = Vector3.new(Mouse.Target.Position.X, Character.UpperTorso.Position.Y, Mouse.Target.Position.Z)
if (Character.UpperTorso.Position - LogPos).magnitude < 8 then
Mouse.Target.Parent.CurDamage.Value += 30
local gui = player.PlayerGui:FindFirstChild("Axe1")
if gui then
gui.Health.Size = UDim2.new(0, 100 - (100 * (Mouse.Target.Parent.CurDamage.Value / Mouse.Target.Parent.NeededDamage.Value)), 0, 25)
gui.Size.Text = "Size: " .. tostring(Mouse.Target.Size.X)
gui.Height.Text = "Height: " .. tostring(math.ceil(Mouse.Target.Size.Y))
gui.Range.Visible = false
end
if Mouse.Target.Parent.CurDamage.Value > Mouse.Target.Parent.NeededDamage.Value then
local mouse = Mouse.Target
local cuttree = player.Character.Axe.cuttree
game.ReplicatedStorage.TreeCutter:FireServer(player,mouse,cuttree)
print("fired server!")
end
else
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("Axe1") then
game.Players.LocalPlayer.PlayerGui:FindFirstChild("Axe1").Range.Visible = true
end
end
else
print("nothing")
end
end
script.Parent.Equipped:Connect(StartGui)
script.Parent.Unequipped:Connect(StopGui)
tool.Activated:Connect(onClick)
SERVER
local function Cut(Part)
Part.Name = "Trunk"
Part.Anchored = false
local Model = Part.Parent
Part.Parent.Top.Anchored = false
Part.Parent = workspace
wait(5)
Model:Destroy()
workspace.SessionInfo.TreesCut.Value = workspace.SessionInfo.TreesCut.Value + 1
end
script.Parent.TreeCutter.OnServerEvent:Connect(function(player, mouse,cuttree)
Cut(mouse)
cuttree.Value = false
end)
Here’s the tool:
Does anyone know what’s happening? Thank you!