(I’m a beginner scripter so please excuse any rookie errors)
Hello, so I’ve returned to a client sided script i made a few months ago (I’m pretty sure I used a tutorial for it) and realised some parts of it need to be server sided, for example the m6d section, but I’m unsure of how to go about splitting the code in two.
p.s I dont get any errors, but once I’ve swung the weapon it deletes itself, and its because of the line a:Destroy()
(I need to put this part into a server sided script for it to work I’m pretty sure)
CODE:
local canDamage = false
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:Wait()
end
local m6d
tool.Equipped:Connect(function()
local a:Weld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
m6d = Instance.new("Motor6D")
m6d.Parent = character:FindFirstChild("Right Arm")
m6d.Name = "RightGrip"
m6d.Part0 = a.Part0
m6d.Part1 = a.Part1
m6d.C0 = a.C0
m6d.C1 = a.C1
a:Destroy()
end)
tool.Unequipped:Connect(function()
m6d:Destroy()
end)
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if not humanoid then
return
end
if humanoid.Parent ~= tool.Parent and canDamage then
humanoid:TakeDamage(5)
end
canDamage = false
end
local slashAnim = Instance.new("Animation")
slashAnim.AnimationId = "rbxassetid://11995880420"
local slashAnimTrack = Animator:LoadAnimation(slashAnim)
local function slash(input, _gameProcessed)
if not (tool.Parent == character) then
return
end
slashAnimTrack:Play()
canDamage = true
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)local tool = script.Parent
local canDamage = false
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:Wait()
end
local m6d
tool.Equipped:Connect(function()
local a:Weld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
m6d = Instance.new("Motor6D")
m6d.Parent = character:FindFirstChild("Right Arm")
m6d.Name = "RightGrip"
m6d.Part0 = a.Part0
m6d.Part1 = a.Part1
m6d.C0 = a.C0
m6d.C1 = a.C1
a:Destroy()
end)
tool.Unequipped:Connect(function()
m6d:Destroy()
end)
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if not humanoid then
return
end
if humanoid.Parent ~= tool.Parent and canDamage then
humanoid:TakeDamage(5)
end
canDamage = false
end
local slashAnim = Instance.new("Animation")
slashAnim.AnimationId = "rbxassetid://11995880420"
local slashAnimTrack = Animator:LoadAnimation(slashAnim)
local function slash(input, _gameProcessed)
if not (tool.Parent == character) then
return
end
slashAnimTrack:Play()
canDamage = true
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)```