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
is this a server script or a local script
Server
look at green271's answer