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

Code working on Studio (LocalScript for destroying blocks and playing sounds) but not on server?

Error: "Handle not found in tool."

--[Made by TheBoxofGhosts]--

--[Locals]--

local mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local folder = workspace.OreBlocks
local sound = tool.Handle:FindFirstChild("Sound")
local oresound = tool.Handle:FindFirstChild("OreSound")

--[Logic]--

local function onMining()
	if mouse.Target and mouse.Target.Name == ("DirtBlock") then
		sound:Play()
		script.Disabled = true
		mouse.Target:Destroy()
		wait(0.3)
		script.Disabled = false
	end
	if mouse.Target and mouse.Target.Name == ("CopperBlock") or mouse.Target and mouse.Target.Name == ("IronBlock") then
		oresound:Play()
		script.Disabled = true
		mouse.Target:Destroy()
		wait(0.3)
		script.Disabled = false
	end
end

tool.Activated:connect(onMining)

4 comments

0

so because tool = script.Parent, when you say "local sound = tool.Handle...", is there a handle under your script?

0

Do you have FE enabled? If so, LocalScripts cannot change anything in the Workspace.

0

TheLuckyZ is right. Filtering will make it so that your local script cannot make changes to the Workspace and affect all clients. To achieve this with filtering, use RemoteEvents in conjunction with server scripts.

0

Also, make sure that this is a LocalScript, else you cant use LocalPlayer.

1 answer

Add WaitForChild. This will yield the current thread until the instance is found.

local handle = tool:WaitForChild("Handle")

If that doesnt work, make sure your tool actualy has a handle, and that its welded to the rest of the tool.

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