I need help with this script everyime I kill another player I receive this message:
--LocalScript:7: Damage is not a valid member of Folder "Players.Player2.Backpack.Gun.Scripts.(Local)"
Here’s the script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local DamageEvent = script.Parent.Parent["(Local)"].Damage
local tool = script.Parent.Parent.Parent
local equipped = false
local IdleAnimId = Instance.new("Animation")
IdleAnimId.AnimationId = tool.Animations.IdleAnim.AnimationId
local ShootAnimId = Instance.new("Animation")
ShootAnimId.AnimationId = tool.Animations.ShootAnim.AnimationId
local IdleAnimation = humanoid:LoadAnimation(IdleAnimId)
local ShootAnimation = humanoid:LoadAnimation(ShootAnimId)
local SFX = tool.FirePoint.Effects.SFX
tool.Equipped:Connect(function()
local holder = tool.Parent
IdleAnimation:Play()
if holder.Name == player.Name then
equipped = true
else
equipped = false
end
end)
tool.Unequipped:Connect(function()
IdleAnimation:Stop()
local holder = tool.Parent
if holder.Name == player.Name then
equipped = true
else
equipped = false
end
end)
mouse.Button1Down:Connect(function()
if equipped then
script.Parent.Shoot:FireServer(mouse.Hit.p)
ShootAnimation:Play()
end
end)
DamageEvent.OnClientEvent:Connect(function()
SFX.Hitmarker:Play()
end)
and the server…
local tool = script.Parent.Parent.Parent
local firePoint = tool.FirePoint
local ShootEvent = script.Parent.Parent["(Local)"].Shoot
local DamageEvent = script.Parent.Parent["(Local)"].Damage
local Effects = firePoint.Effects
local SFX = Effects.SFX
local range = 300
local damageAmount = tool.Configs.GunComponents.Damage.Value
ShootEvent.OnServerEvent:Connect(function(player, mouseHit)
SFX.Fire:Play()
Effects.MuzzleEffect.Enabled = true
Effects.MuzzleFlash.Enabled = true
wait(0.05)
Effects.MuzzleEffect.Enabled = false
Effects.MuzzleFlash.Enabled = false
if player.Name == tool.Parent.Name then
local filterType = Enum.RaycastFilterType.Exclude
local filter = RaycastParams.new()
filter.FilterType = filterType
filter.FilterDescendantsInstances = {tool.Parent}
local raycast = workspace:Raycast(firePoint.Position, (mouseHit - firePoint.Position).Unit * range, filter )
if raycast then
local hitPart = raycast.Instance
print(hitPart.Name)
local char = hitPart.Parent
local hum = char:FindFirstChild("Humanoid")
if char.Name ~= tool.Parent.Name and hum then
hum:TakeDamage(damageAmount)
DamageEvent:FireClient(player)
end
end
end
end)