Would this script work?
The first is a LocalScript in StarterCharacterScripts, the second is a normal script in ServerScriptService.
-- In StarterCharacterScripts, LocalScript.
local ts = game:GetService("TweenService")
local char = script.Parent
local mouse = plr:GetMouse()
local event = game.ReplicatedStorage.AttackEvent
local canAttack = true
function reload()
canAttack = false
wait(RELOAD_TIME)
canAttack = true
end
mouse.Button1Down:Connect(function()
if (char.HumanoidRootPart.Position - mouse.CFrame.Position).Magnitude <= 30 then
if canAttack then
event:FireServer(mouse.CFrame.Position, char.HumanoidRootPart.Position)
reload()
end
end
end
ServerScript…
-- In ServerScriptService, Normal Script.
local ts = game:GetService("TweenService")
local event = game.ReplicatedStorage.AttackEvent
local STUDS_AWAY = 3 -- The amount of studs away you want the part to start away from the character.
local RANGE = 30 -- The range of the attack
local SPEED_OF_ATTACK = 3 -- 3 studs per second
event.OnServerEvent:Connect(function(plr, mousepos, playerpos)
local distance = (playerpos - mousepos).Magnitude
if distance <= RANGE and distance > STUDS_AWAY then
local attack = Instance.new("Part", game.Workspace)
attack.Name = "Attack"
attack.Shape = "Ball"
attack.Position = playerpos:lerp(mousepos, STUDS_AWAY/distance)
local Properties = {
position = mousepos
}
local Info = TweenInfo.new(distance/SPEED_OF_ATTACK, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1, false, 0)
local tween = ts:Create(attack, Info, Properties):Play()
attack:Destroy()
end
end
I just wanted to know.
Maybe someone can test it?