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

How do I make my axe tool script work in-game? It works fine in studio. zzzzzzzzzzz

My script works perfect inside studio, but when I run it in-game it doesn't work. Does anyone know why and can you explain to me what is wrong in my script?

Here is my script:

local playerName = script.Parent.Parent.Parent.Name
local player = game.Players:FindFirstChild(playerName)
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function ()
	local target = mouse.Target
	if target then
		
		if target.Name == "Trunk" or target.Name == "Log" then
			target.Parent.hits.Value = target.Parent.hits.Value + 1
			if target.Parent.hits.Value == 5 then
				target.Anchored = false
				workspace.WorldScripts.StatsFolder:WaitForChild(playerName).Logs.Value = workspace.WorldScripts.StatsFolder:WaitForChild(playerName).Logs.Value + 1
				wait(1)
				for _, object in pairs(target.Parent:GetChildren()) do
					object.CanCollide = false
				end
			end
			
		end
		
	end
end)

3 comments

0

is this a server script or a local script

0

Server

0

look at green271's answer

1 answer

✓ Accepted answer

###GetMouse

GetMouse can only be called from the client. It returns the mouse that the client is using, which is why it will not work on the server. It'll always be nil.

You can use RemoteEvents and other methods to accomplish your task.

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