I am trying to make an RPG game but I have a few scripts that work in studio but not in a server. One script is a sword animation for swinging. It swings perfectly in the studio and it is my own animation. It has the animation inside it and it is in a tool in the starter pack. Here is the code:

repeat wait() until game.Players.LocalPlayer.Character

local CanAttack = true

script.Parent.DamagePart.Touched:connect(function(p)
	
	if script.Parent.CanDamage.Value == true then
		script.Parent.CanDamage.Value = false
		game.Workspace.Rouge.Humanoid:TakeDamage(math.random(3,10))
		
	end
	
end)


script.Parent.Activated:connect(function()

local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) 
	
	if CanAttack == true then
		
		attack:Play()
		CanAttack = false
		wait(0.5)
		attack:Stop()
		CanAttack = true
		script.Parent.CanDamage.Value = true
		
	end

end)

Another code is for a mob damaging you on contact. It is a normal script in the mob named "Rouge".

repeat wait() until game.Players.LocalPlayer.Character

players = nil; --Where we are going to store all the players
dummy = game.Workspace.Rouge; --Dummy reference
currentPlayerFollowing = nil; --The current player the zombie is following
damage = 2; --Change this for more damage if you want
 
function touched(hit)
  --pcall allows for errors to be disregarded so you don't have to worry about random output errors
   if pcall(function() if hit.Parent.Humanoid ~= nil then end end) then --If the character's health storage is there
   	pcall(function() hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage end); --Do damage
   end
end

Please help me if you can!

6 comments

0

Can you edit your question to where I can actually see the code correctly please?

1

Is your script a LocalScript or a Script? If it is a LocalScript then you can't use game.Players.LocalPlayers in a server Script, only a LocalScript.

0

Please edit your question and add the scripts in a code block.

0

how do i put it in a code block?

0

nevermind i figured it out

0

the first script is a local script and the second is a server script