ight nothing pops up, ill give you my scripts. Hammer script: -- Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
-- Variables
local player = Players.LocalPlayer
local tool = script.Parent
local deleteToolGui = ReplicatedStorage:WaitForChild("DeleteToolGui")
local currentTarget = nil
local currentGuiInstance = nil
local currentHighlight = nil
-- FORWARD DECLARATIONS (The Fix!)
-- We declare the function names first so they can call each other.
local showHighlight
local hideHighlight
local showGui
local hideGui
local onMouseClick
-- Function Definitions
hideHighlight = function()
if currentHighlight then
currentHighlight:Destroy()
currentHighlight = nil
end
end
hideGui = function()
if currentGuiInstance then
currentGuiInstance:Destroy()
currentGuiInstance = nil
end
end
showHighlight = function(model)
if not model then return end
-- Remove existing highlight
hideHighlight()
-- Create a new highlight for the entire model
local highlight = Instance.new("Highlight")
highlight.FillTransparency = 0.7
highlight.OutlineTransparency = 0.1
highlight.OutlineColor = Color3.new(1, 0, 0) -- Red
highlight.Parent = model
currentHighlight = highlight
end
showGui = function(character)
if not character or not character:FindFirstChild("Torso") then return end
-- Remove existing GUI
hideGui()
-- Clone and parent the GUI to the worker's torso
local guiClone = deleteToolGui:Clone()
guiClone.Parent = character.Torso
currentGuiInstance = guiClone
-- Get buttons from the GUI
local deleteButton = guiClone.Buttons:WaitForChild("DeleteButton")
local pickupButton = guiClone.Buttons:WaitForChild("PickupButton")
-- Delete Button Logic
deleteButton.MouseButton1Click:Connect(function()
print("🔴 Delete button clicked!") -- Debug print
ReplicatedStorage.DeleteWorkerEvent:FireServer(character)
hideHighlight()
hideGui()
end)
-- Pickup Button Logic
pickupButton.MouseButton1Click:Connect(function()
print("🟢 Pickup button clicked!") -- Debug print
ReplicatedStorage.PickupWorkerEvent:FireServer(character)
hideHighlight()
hideGui()
end)
end
onMouseClick = function()
if not tool.Parent or tool.Parent ~= player.Character then return end
local mouse = player:GetMouse()
local target = mouse.Target
local character = target and target:FindFirstAncestorWhichIsA("Model")
-- Check if clicking on a worker model
if character and character:FindFirstChild("WorkerConfig") then
currentTarget = character
showHighlight(currentTarget)
showGui(currentTarget)
else
-- If we clicked on anything else, hide the GUI and reset the target
hideGui()
currentTarget = nil
end
end
-- Main Loop for Hover Highlighting
local function onHeartbeat()
if not tool.Parent or tool.Parent ~= player.Character then return end
-- If a GUI is currently active (we clicked a worker), don't update the hover highlight.
if currentGuiInstance then return end
local mouse = player:GetMouse()
local target = mouse.Target
local character = target and target:FindFirstAncestorWhichIsA("Model")
-- Check if hovering over a worker model
if character and character:FindFirstChild("WorkerConfig") then
-- Only update the highlight if we are hovering over a NEW worker
if currentHighlight and currentHighlight.Parent == character then
-- Do nothing, already highlighted
else
showHighlight(character)
end
else
hideHighlight()
end
end
-- Connections
tool.Equipped:Connect(function()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
-- Check if it's a left click and if the click wasn't already used by a GUI element
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
onMouseClick()
end
end)
-- Connect the hover check
RunService.Heartbeat:Connect(onHeartbeat)
end)
tool.Unequipped:Connect(function()
-- Clean up when tool is put away
hideHighlight()
hideGui()
currentTarget = nil
-- Note: We can't easily disconnect anonymous functions from UserInputService/RunService here,
-- but the functions themselves check if the tool is equipped (if not tool.Parent...), so it's okay.
end) WorkerAction script: -- ServerScriptService > WorkerActionsServer.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local WorkersFolder = ReplicatedStorage:WaitForChild("Workers") -- Your worker templates
-- RemoteEvents
local deleteEvent = ReplicatedStorage:WaitForChild("DeleteWorkerEvent")
local pickupEvent = ReplicatedStorage:WaitForChild("PickupWorkerEvent")
-- Helper: Check if the worker belongs to the player (adjust for your plot system!)
local function isPlayerOwner(player, workerModel)
local plotName = player:GetAttribute("AssignedPlot")
print("📍 Player's plot:", plotName) -- Debug print
local plot = workspace.Plots:FindFirstChild(plotName)
if not plot then
print("❌ Plot not found") -- Debug print
return false
end
local base = plot:FindFirstChild("Base")
if not base then
print("❌ Base not found in plot") -- Debug print
return false
end
local isOwner = workerModel:IsDescendantOf(base)
print("✅ Is worker in base?", isOwner) -- Debug print
return isOwner
end
-- Handle Delete
deleteEvent.OnServerEvent:Connect(function(player, workerModel)
print("💣 Delete event received from", player.Name) -- Debug print
if not workerModel or not workerModel:IsA("Model") then
print("❌ Delete: Invalid worker model")
return
end
if not isPlayerOwner(player, workerModel) then
print("❌ Delete: Player not owner of", workerModel.Name)
return
end
workerModel:Destroy()
print("✅ Deleted:", workerModel.Name)
end)
-- Handle Pickup
pickupEvent.OnServerEvent:Connect(function(player, workerModel)
-- Validate: Is the worker real? Does the player own it?
pickupEvent.OnServerEvent:Connect(function(player, workerModel)
print("📦 Pickup event received from", player.Name) -- Debug print
if not workerModel or not workerModel:IsA("Model") then
print("❌ Pickup: Invalid worker model")
return
end
if not isPlayerOwner(player, workerModel) then
print("❌ Pickup: Player not owner of", workerModel.Name)
return
end
-- Tool creation logic...
end)
-- Get the worker template from your WorkersFolder
local workerName = workerModel.Name
local workerTemplate = WorkersFolder:FindFirstChild(workerName)
if not workerTemplate then return end
-- Create a tool (reuse your existing tool-creation logic!)
local tool = Instance.new("Tool")
tool.Name = workerName
tool.RequiresHandle = false
-- Add the worker model to the tool (for placement later)
local workerClone = workerTemplate:Clone()
workerClone.Name = "WorkerModel"
workerClone.Parent = tool
-- Optional: Copy AnimationId (if your workers use it)
local animId = workerClone:FindFirstChild("AnimationId")
if animId then
animId:Clone().Parent = tool
end
-- Give the tool to the player's backpack
tool.Parent = player:WaitForChild("Backpack")
-- Delete the placed worker (since it's now in the inventory)
workerModel:Destroy()
print(`{player.Name} picked up {workerName}`)
end)