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

LocalScript animation tool doesn't work when copied from Lighting. How can I fix this?

Asked by 4 years ago
Edited 4 years ago

To clarify, I'm a massive noob. It's likely I'm making a mistake that shows that.

The tool is intended to play a simple animation holding a simple object. It works fine when placed in StarterPack.

However, I do not want all players to have access to it. I want it to be accessible only by using Kohl's admin, which copies tools from Lighting.

The tool, when copied from Lighting (or dragged into the player backpack in Explorer), does not function. It just holds the object as if there were no scripts.

The following is the contents of the LocalScript. It is not my code, but perhaps it's relevant:

local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local tool = script.Parent

local animation = humanoid:LoadAnimation(tool.Animation)

tool.Equipped:Connect(function()
    animation:Play() -- Play Animation when tool is equipped
end)

tool.Unequipped:Connect(function() -- Unequipped event
    animation:Stop() -- Stop Animation when tool is no longer equipped
end)

FilteringEnabled did not appear to cause any change in behavior.

I appreciate all ideas, thanks!

Edit1:

I attempted to reenable the script once equipped, having disabled it in Lighting. Here is the amended code:

local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local tool = script.Parent

local animation = humanoid:LoadAnimation(tool.Animation)

tool.Equipped:connect(function()
    script.Parent.Disabled = false
end)

tool.Equipped:Connect(function()
    animation:Play() -- Play Animation when tool is equipped
end)

tool.Unequipped:Connect(function() -- Unequipped event
    animation:Stop() -- Stop Animation when tool is no longer equipped
end)

It does not work, and Script Analysis shows no errors.

0
Simple answer. Have the script disabled while in lighting, and then un-disable is when it gets put in the player's inventory! Let me know if this helped! I have no idea why this is, but it always seems to solve all my issues. Happy scripting, Tim ThatDevTim 188 — 4y
0
I appreciate the advice! But I'm not sure how to do that. Is it a few lines I can add to the existing code? TheValiant 5 — 4y
0
I edited the post with updated broken code. TheValiant 5 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Working on what Tim said you will need to disable the script before it goes into lighting and the enable it when it comes out of lighting. You will need a separate script to enable it. But, first when you send it to lighting, create this new line before it (wherever you might be sending it to lighting):

-- script.Parent = game.Lighting
-- script.Disabled = true

Then, for your enabling phase:

game.Players.PlayerAdded:Connect(function(plr)
    script.Parent:GetPropertyChangedSignal("Parent"):Connect(function(parent)
        if parent == plr.Character or plr.Backpack then
              script.Parent.Disabled = false
        end
     end
end

NB - This is not a functional script, for script 2 it must be inside the script and for script 1 it must be in customised to your moving script,

Ad
Log in to vote
0
Answered by 4 years ago

Disable RequiresHandle value in the tool, if it doesn't have a handle.

Answer this question