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)
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 RemoteEvent
s and other methods to accomplish your task.