how do i load an animation on tool activation?
I have the animation and im trying LoadAnimation but it doesnt work, What do i do?
how do i load an animation on tool activation?
I have the animation and im trying LoadAnimation but it doesnt work, What do i do?
Please post your current progress with your script so we can help you.
local model = script.Parent
local Debounce = true
local Delay = 5
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild(âHumanoidâ)
local AnAnimation = model.Animation
local animTrack = humanoid:LoadAnimation(AnAnimation)
script.Parent.Activated:Connect(function()
if Debounce then
Debounce = falseanimTrack:Play()
model.Handle.BombBeeping:Play()
redlight = Instance.new(âSpotLightâ)
redlight.Color = Color3.fromRGB(255,0,0)
redlight.Parent = model.Handle
redlight.Brightness = 100
redlight.Range = 100
redlight.Face = âBottomâ
wait(1)
model.Handle.BombBeeping:Stop()
model.Handle.Boom:Play()
model.MainVest.CanCollide = false
ex = Instance.new(âExplosionâ)
ex.Position = script.Parent.MainVest.Position
ex.Parent = workspace
ex.BlastRadius = 10
redlight:Destroy()
wait(5)
Debounce = true
end
end)
The code seems correct. It may be an asset loading issue, are there any errors in the output? Do you own the animation?
also i own the animation.
Try this:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Tool = script.Parent
local Animation = Tool:WaitForChild("Animation")
local AnimationTrack = Humanoid:LoadAnimation(Animation)
local Debounce = true
local Delay = 5
local function OnActivated()
if Debounce then
Debounce = false
AnimationTrack:Play()
Tool.Handle.BombBeeping:Play()
local redlight = Instance.new("SpotLight")
redlight.Color = Color3.fromRGB(255,0,0)
redlight.Parent = model.Handle
redlight.Brightness = 100
redlight.Range = 100
redlight.Face = "Bottom"
wait(1)
Tool.Handle.BombBeeping:Stop()
Tool.Handle.Boom:Play()
Tool.MainVest.CanCollide = false
local ex = Instance.new("Explosion")
ex.Position = script.Parent.MainVest.Position
ex.Parent = workspace
ex.BlastRadius = 10
redlight:Destroy()
wait(Delay)
Debounce = true
end
end
Tool.Activated:Connect(OnActivated)
I cleaned it up a bit
Also, please read this guide in posting code on the forum:
Do you have another variable called âPlayerâ or something that changes what the variable Player is? As far as I know, that code is supposed to be working fine
Edit:
Is this a local script or normal script?
this isnt a local script, its a normal script. (btw i dont have any other variable that changes the player variable)
This is the issue then. Change this to a local script and it should work fine.
Players.LocalPlayer
is only accessible to local scripts.
it works but, The redlight and the explosion are local meaning that they cannot be seen by others and also it cannot effect others. What do i do to change it so the light and the explosion werent local??
also if the player equipped the tool, is the toolâs parent the player?
If you really need to use a server script, and the tool is in StarterPack, you can index Player as:
local player = script.Parent.Parent.Parent -- Tool>Backpack>Player
You could use remote events to tell the server that you activated the script and add sanity checks to avoid exploits.
@20amir02 Itâs better to use a local script, as special effects such as explosions may add up to server load or impact performance on the server. Using a local script and remote events will allow a client-server-client communication so that the server never has to handle the special effects and sacrifice performance.
Edit:
Iâm creating a demo place file, pleaase wait.
Hereâs an example of how to show other players effects that are happening locally:
Special Effects Router.rbxl (19.4 KB)
The good thing about this is, the server does not sacrifice any performance because everything (explosions, lights, sounds, etc) is being rendered on the clients and not the server. Itâs a good practice to only show effects locally and never the server!
If you have questions about this, feel free to ask.
Itâs actually a bad thing because the explosion is supposed to effect people, instead it effects the local user.
The explosion will affect other players. Itâs the whole point of my demo file. The explosion will happen locally, and the server will tell other clients to create the same explosion for them locally. The server never has to have the explosion object. You just need to add sanity checks on the server to avoid exploiters taking advantage of disabling the replication script. If the players are within the radius of the explosion, they should have taken damage, else the server will force kill those players etc.
can u edit ur demo file so it also adds a spotlight and an animation?
Iâd just like to remind you that asking people to create a whole script is not allowed.
My demo file was just a reference to give you an idea, not for me to do all the work. However since I have time, I did my best to make it do what the original script does. I have no idea how the environment of your game works or how it looks like, so expect something not to work right away (probably just object names)
Special Effects Router.rbxl (19.8 KB)
I have provided more than enough resources for this thread. Itâs up to you on how to use them.
Errors, This is the error i got: