Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Made a click-to-attack script for a morph, how do I make it damage others server-sided?

I am a beginner to Lua and I've ran into a bit of a roadblock.

To summarize the situation:

The morph model is in ReplicatedStorage. The script is a local script and it's in the model within ReplicatedStorage so it can be replicated to the players that click on the morph button. It performs the attack animation and damages other players normally on the client-side, but doesn't affect the server.

I can't figure out a good way to turn the script into something so the damage will affect the server instead of the client.

Here's the contents of the local script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local dmg = true
local hmnoid = script.Parent.Humanoid
local Attack = Instance.new("Animation")
Attack.AnimationId = "http://www.roblox.com/asset/?id=4602669454"
local AttackAnim = hmnoid:LoadAnimation(Attack)

Mouse.Button1Down:connect(function()
	dmg = true
  AttackAnim:Play()
  script.Parent.RHand.Touched:connect(function(hit)
   if hit.Parent.Humanoid and dmg == true then
    hit.Parent.Humanoid:TakeDamage(20)
    dmg = false
   end
  end)
end)

If anyone has any tips or suggestions for this, I would greatly appreciate it!

1 answer

You have to use a Server Script to damage the humanoid on the server. And DO NOT just fire a remote to the server and damage the humanoid, the server should be the one who checks if they got touched or not.

Though you could fire a remote to tell the server when you are preforming the attack, and in that period the server checks if you hit anything.

1 comment

0

Thank you for answering. I attempted putting the damage part of the script in a server script and the attack animation in a separate local script, making it so that when the attack animation runs in the local script it would change the Disabled property of the damage server script to false. This time it would run the animation but wouldn't do any damage. Might try the remote tactic instead.

This discussion is preserved as it was. New answers, comments, and votes are closed.