The issue I’m having is that it simply won’t play an animation because I can’t wrap my head around this code. I’ve been looking at examples and stuff for like two hours and just can’t understand how a bindable event receives a player in some examples and not in others. I’ve tried a lot of things and have gotten to the point where I feel like just deleting all the code and doing something else. Also, this is untested but I think my code might also let the animation run twice if somebody else joins and resets, but again I haven’t tested if that part is true.
Code for detecting if something is touched and then sending who touched it to the other script:
local e = 1
local BindableEvent = game.Workspace:WaitForChild("bindable")
function touchedChar(hit) -- Creating a function
if hit.Parent:FindFirstChild("Humanoid") then -- Detects a humanoid inside the player's character
if e == 1 then
print("e")
BindableEvent:Fire(hit.Parent)
end
local e = 0-- Making something happen when a part is touched
end
end
for _,Part in ipairs(script.Parent:GetDescendants()) do
if Part:IsA("BasePart") then
Part.Touched:Connect(touchedChar)
end
end
local Player = game.Players.LocalPlayer
local Char = Player.Character
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
Char.Humanoid.Died:Connect(function()
local e = 1
end)
end)
end)
Code for running the animation and receiving the bindable event:
local BindableEvent = game.Workspace:WaitForChild("bindable")
local Players = game:GetService("Players")
BindableEvent.Event:Connect(function(player)
local animation = game.Players.player.Humanoid:LoadAnimation(script.Animation)
animation:Play()
end)