Hello, I recently returned to developing on Roblox
Keep in mind this is my first post
I’ve created a system when the player presses ‘e’, it damages another player. The problem is that I can’t figure out how to damage that player which the weapon is touching without it damaging the player itself.
I’ve tried looking on the dev forums and scriptinghelpers, but the results either spammed the console and still damaged the player or didn’t hurt the other player at all. I’ve also tried disabling and enabling the damage script, it worked, but it won’t register as a kill.
Again this is my first post, sorry if this is not enough detail, I can provide more if requested.
Thank You For Your Time !
Local Script In The Tool (Problem At The Near Bottom):
uis = game:GetService("UserInputService")
local Tool = script.Parent
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local DefaultFoV1 = 70
local DefaultFoV2 = 50
local TweenService = game:GetService("TweenService")
local Properties1 = {FieldOfView = DefaultFoV1 - 20}
local Properties2 = {FieldOfView = DefaultFoV2 + 20}
local Info1 = TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
local Info2 = TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
local T1 = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info1, Properties1)
local T2 = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info2, Properties2)
local eq=false
local db=false
local Players={}
MeleeDamage = game.ReplicatedStorage:WaitForChild("MeleeDamage")
Aimmed = false
Waitting = false
Clicking = false
Tool.Equipped:Connect(function(Mouse)
Mouse.Button2Up:Connect(function()
Aimmed = false
T2:Play()
wait(0.1)
game.Workspace.CurrentCamera.FieldOfView = 70
local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Aimmed)
anim1:Play()
anim2:Stop()
Tool.Sprint.Disabled = false
script.Parent.SprintCamera.Disabled = true
script.Parent.WalkCamera.Disabled = false
end)
end)
Tool.Equipped:Connect(function(Mouse)
Mouse.Button2Down:Connect(function()
Aimmed = true
T1:Play()
wait(0.25)
game.Workspace.CurrentCamera.FieldOfView = 50
Tool.Sprint.Disabled = true
wait()
local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Aimmed)
anim1:Stop()
anim2:Play()
char.Humanoid.WalkSpeed = 15
script.Parent.SprintCamera.Disabled = true
script.Parent.WalkCamera.Disabled = false
end)
end)
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
Clicking = true
end)
end)
--Tool.Equipped:Connect(function(Mouse)
-- Mouse.Button1Down:Connect(function()
-- if Aimmed == false then
-- char.Humanoid.WalkSpeed = 15
-- local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.ShootAimmed)
-- local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Shoot)
-- anim1:Play()
-- anim2:Stop()
-- Tool.Sprint.Disabled = true
-- else
-- char.Humanoid.WalkSpeed = 15
-- local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.ShootAimmed)
-- local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Shoot)
-- anim2:Play()
-- anim1:Stop()
-- Tool.Sprint.Disabled = true
-- end
-- end)
--end)
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Up:Connect(function()
char.Humanoid.WalkSpeed = 15
Clicking = false
Tool.Sprint.Disabled = false
script.Parent.SprintCamera.Disabled = true
script.Parent.WalkCamera.Disabled = false
end)
end)
Tool.Equipped:Connect(function(Mouse)
Mouse.Button2Down:Connect(function()
Aimmed = true
local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Aimmed)
Tool.Sprint.Disabled = true
anim1:Stop()
anim2:Play()
char.Humanoid.WalkSpeed = 15
script.Parent.SprintCamera.Disabled = true
script.Parent.WalkCamera.Disabled = false
end)
end)
Crouching = false
animtrack3 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
animtrack1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Crawling)
animtrack2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.CrawlIdle)
--local function ChangeCameraOffset(Offset)
--if not char then char = plr.char or plr.CharacterAdded:Wait() end
--local Humanoid = char:WaitForChild("Humanoid")
--local Tween = TweenService:Create(Humanoid, TweenInfo.new(0.5), {CameraOffset = Offset})
--Tween:Play()
--end
--Tool.Equipped:Connect(function(Mouse)
--Mouse.KeyDown:connect(function(key)
--if key == "c" then
--if Crouching == false then
--Tool.Sprint.Disabled = true
--Crouching = true
--animtrack1:Play()
--animtrack2:Stop()
--animtrack3:Stop()
--script.Parent.SprintCamera.Disabled = true
--script.Parent.WalkCamera.Disabled = true
--ChangeCameraOffset(Vector3.new(0, -1, 0))
--repeat
--char.Humanoid.WalkSpeed = 8
--wait()
--until Crouching == false
--else
--Tool.Sprint.Disabled = false
--Crouching = false
--animtrack1:Stop()
--animtrack2:Stop()
--animtrack3:Play()
--ChangeCameraOffset(Vector3.new(0, 0, 0))
--char.Humanoid.WalkSpeed = 15
--script.Parent.SprintCamera.Disabled = true
--script.Parent.WalkCamera.Disabled = false
--end
--end
--end)
--end)
Tool.Equipped:Connect(function(Mouse)
Mouse.KeyDown:connect(function(key)
if key == "q" then
if Aimmed == false then
print("aimmed")
Aimmed = true
T1:Play()
Tool.Sprint.Disabled = true
wait()
local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Aimmed)
anim1:Stop()
anim2:Play()
char.Humanoid.WalkSpeed = 15
script.Parent.SprintCamera.Disabled = true
script.Parent.WalkCamera.Disabled = false
else
print("not aimmed")
Aimmed = false
T2:Play()
local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
local anim2 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Aimmed)
anim1:Play()
anim2:Stop()
Tool.Sprint.Disabled = false
script.Parent.SprintCamera.Disabled = true
script.Parent.WalkCamera.Disabled = false
end
end
end)
end)
Tool.Equipped:Connect(function(Mouse)
Mouse.KeyDown:connect(function(key)
if key == "e" then
if Waitting == false then
if Clicking == false then
Waitting = true
local Damage = 35
local anim1 = hum:LoadAnimation(game.ReplicatedStorage.Animations.Melee)
anim1:Play()
wait(0.04)
script.MeleeDamage:FireServer(Damage)
print("Fired")
wait(0.7)
anim1:Stop()
wait(0.05)
Waitting = false
end
end
end
end)
end)
uis.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Aimmed = false
end
end)