Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)
0
is this a server script or a local script User#23365 30 — 5y
0
Server devisings 58 — 5y
0
look at green271's answer User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by
green271 635 Moderation Voter
5 years ago

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.

Ad

Answer this question