So, I want the animations to play (they’re made by the owner) but they don’t load for me. Any thing related to this? Or what is wrong with my script? Please respond.
Module Code:
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local projectiles = ReplicatedStorage.Projectiles
local cooldown = false
local spell = {}
function spell.HandleNewSpell(spellName, dmg, plr, animId)
local projectileExists = projectiles:FindFirstChild(spellName)
if projectileExists and not cooldown then
cooldown = true
if projectileExists.Name == "Water" then
local char = plr.Character or plr.CharacterAdded:Wait()
local projectile = projectileExists:Clone()
local velocity = Instance.new("BodyVelocity")
local weld = Instance.new("WeldConstraint")
local animation = Instance.new("Animation")
local animator = char.Humanoid.Animator or Instance.new("Animator", char.Humanoid)
local offset = CFrame.new(0,0,-4)
animation.AnimationId = "rbxassetid://"..animId
local animTrack = animator:LoadAnimation(animation)
weld.Part0 = projectile
weld.Part1 = char.HumanoidRootPart
weld.Parent = projectile
char.Humanoid.WalkSpeed = 0
animTrack:Play()
projectile.CFrame = char.HumanoidRootPart.CFrame * offset * CFrame.Angles(90,0,0)
projectile.Parent = workspace.Projectiles
projectile.Sound:Play()
velocity.Velocity = Vector3.new(0,0,0)
velocity.Parent = projectile
animTrack.Stopped:Connect(function()
weld:Destroy()
char.Humanoid.WalkSpeed = 16
projectile.CanCollide = false
velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
velocity.Velocity = char.HumanoidRootPart.CFrame.LookVector*500
projectile.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local debounce = false
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= dmg
projectile:Destroy()
if player then
local frame = player.PlayerGui.ScreenGui.WaterSplashFrame
frame.BackgroundTransparency = 0
local info = TweenInfo.new(2.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0,false,0)
local goals = {BackgroundTransparency = 1}
local tween = TweenService:Create(frame,info,goals)
tween:Play()
end
end
end)
Debris:AddItem(projectile, 10)
end)
elseif projectileExists.Name == "Fire" then
cooldown = true
local char = plr.Character or plr.CharacterAdded:Wait()
local projectile = projectileExists:Clone()
local animation = Instance.new("Animation")
local animator = char.Humanoid.Animator or Instance.new("Animator", char.Humanoid)
local offset = CFrame.new(0,-1.5,0)
animation.AnimationId = "rbxassetid://"..animId
local animTrack = animator:LoadAnimation(animation)
char.Humanoid.WalkSpeed = 0
animTrack:Play()
projectile.CFrame = char.HumanoidRootPart.CFrame * offset
local info = TweenInfo.new(1.25,Enum.EasingStyle.Back,Enum.EasingDirection.InOut,0,false,0)
local goals = {Size = Vector3.new(50,50,50), Transparency = 1}
local tween = TweenService:Create(projectile,info,goals)
projectile.Size = Vector3.new(0,0,0)
projectile.Transparency = 0
projectile.CanCollide = false
projectile.Parent = workspace.Projectiles
wait(0.385)
tween:Play()
projectile.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local debounce = false
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= dmg
projectile:Destroy()
if player then
local cjar = player.Character or player.CharacterAdded:Wait()
local old_walk = cjar.Humanoid.WalkSpeed
cjar.Humanoid.WalkSpeed = 0
task.wait(1.5)
cjar.Humanoid.WalkSpeed=game.StarterPlayer.CharacterWalkSpeed
end
end
end)
task.wait(0.5)
projectile.Sound:Play()
animTrack.Stopped:Connect(function()
char.Humanoid.WalkSpeed = 16
end)
tween.Completed:Connect(function()
task.wait(0.4)
projectile:Destroy()
end)
elseif projectileExists.Name == "Wind" then
local char = plr.Character or plr.CharacterAdded:Wait()
local projectile = projectileExists:Clone()
local weld = Instance.new("WeldConstraint")
local animation = Instance.new("Animation")
local animator = char.Humanoid.Animator or Instance.new("Animator", char.Humanoid)
local offset = CFrame.new(0,5,0)
animation.AnimationId = "rbxassetid://"..animId
local animTrack = animator:LoadAnimation(animation)
weld.Part0 = projectile
weld.Part1 = char.Torso
weld.Parent = projectile
char.Humanoid.WalkSpeed = 0
animTrack:Play()
projectile.CFrame = char.HumanoidRootPart.CFrame * offset * CFrame.Angles(0,0,0)
projectile.Parent = workspace.Projectiles
projectile.Sound:Play()
projectile.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local debounce = false
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= dmg
elseif hit.Parent.Name == "Projectiles" then
hit:Destroy()
end
end)
animTrack.Stopped:Connect(function()
weld:Destroy()
projectile.Sound:Stop()
char.Humanoid.WalkSpeed = 16
projectile:Destroy()
end)
end
task.wait(3)
cooldown = false
else
warn("Spell "..spellName.." dosen't exist or spell handler is on cooldown.")
end
end
return spell
Server Code:
local RS = game:GetService("ReplicatedStorage")
local Events = RS:WaitForChild("Events")
local doSpellEvent = Events:WaitForChild("DoSpellEvent")
local sprintEvent = Events:WaitForChild("SprintEvent")
local endSprintEvent = Events:WaitForChild("EndSprintEvent")
local spell = require(script.SpellModule)
doSpellEvent.OnServerEvent:Connect(function(plr, spellName, dmg, animId)
spell.HandleNewSpell(spellName, dmg, plr, animId)
end)
sprintEvent.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid") or Instance.new("Humanoid", char)
h.WalkSpeed = 32
end)
endSprintEvent.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid") or Instance.new("Humanoid", char)
h.WalkSpeed = 16
end)
Client Code:
local PLRS = game:GetService("Players")
local SG = game:GetService("StarterGui").ScreenGui
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local plr = PLRS.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Events = RS:WaitForChild("Events")
local doSpellEvent = Events:WaitForChild("DoSpellEvent")
local sprintEvent = Events:WaitForChild("SprintEvent")
local endSprintEvent = Events:WaitForChild("EndSprintEvent")
local sprintAnimHandler = nil
local running = false
local spellRunning = false
local function fireSpellEvent(spellName, dmg, animId)
doSpellEvent:FireServer(spellName, dmg, animId)
end
UIS.InputBegan:Connect(function(input, gpe)
if gpe then
return
end
if not gpe then
if UIS.KeyboardEnabled and UIS.MouseEnabled then
plr.PlayerGui.ScreenGui.MobileSpellButtonList.Visible = false
plr.PlayerGui.ScreenGui.MobileToggle.Visible = false
if input.KeyCode == Enum.KeyCode.E then
if running then
running = false
sprintAnimHandler:Stop()
endSprintEvent:FireServer()
end
spellRunning = true
fireSpellEvent("Water", 42, 9841022808)
task.wait(1)
spellRunning = false
elseif input.KeyCode == Enum.KeyCode.X then
if running then
running = false
sprintAnimHandler:Stop()
endSprintEvent:FireServer()
end
spellRunning = true
fireSpellEvent("Fire", 60, 9818602099)
task.wait(1)
spellRunning = false
elseif input.KeyCode == Enum.KeyCode.Q then
if running then
running = false
sprintAnimHandler:Stop()
endSprintEvent:FireServer()
end
spellRunning = true
fireSpellEvent("Wind", 101, 9823632055)
task.wait(4)
spellRunning = false
elseif input.KeyCode == Enum.KeyCode.LeftShift and not spellRunning and not running then
if char.Humanoid.MoveDirection.Magnitude > 0 then
running = true
sprintEvent:FireServer()
sprintAnimHandler = char.Humanoid.Animator:LoadAnimation(char.Animation)
sprintAnimHandler:Play()
end
end
elseif UIS.TouchEnabled then
for i, v in ipairs(SG.MobileSpellButtonList:GetChildren()) do
if v:IsA("TextButton") then
v.Visible = true
end
end
plr.PlayerGui.ScreenGui.MobileSpellButtonList.Visible = true
plr.PlayerGui.ScreenGui.MobileToggle.Visible = true
end
else
return
end
end)
UIS.InputEnded:Connect(function(key,gpe)
if gpe then
return
end
if key.KeyCode == Enum.KeyCode.LeftShift and running then
running = false
sprintAnimHandler:Stop()
endSprintEvent:FireServer()
end
end)