Hello! new developer here, so these scripts are for the hitbox, but for some reason when i fire server, it gets all the players hrp instead of the player firing the server, please help!
(omg my English is terrible)
Server script
local rep = game:GetService("ReplicatedStorage")
local remotes = rep:WaitForChild("remotes")
local hitposition = nil
local Attack = remotes.Event
local hitting = remotes.goback
local green = false
Attack.OnServerEvent:Connect(function(plr, damage,x,y,z)
hitting.OnServerEvent:Connect(function(plr,hitpos)
hitposition = hitpos
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.Red()
part.Size = Vector3.new(x,y,z)
part.CFrame = hitposition
part.Material = "Neon"
part.Transparency = 0.5
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and not green then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
green = true
part.BrickColor = BrickColor.Green()
end
end)
wait(0.1)
game.Debris:AddItem(part,1)
local part2 = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.Red()
part.Size = Vector3.new(x,y,z)
part.CFrame = hitposition
part.Material = "Neon"
part.Transparency = 0.5
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and not green then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
green = true
part.BrickColor = BrickColor.Green()
end
end)
wait(0.1)
game.Debris:AddItem(part2,1)
local part3 = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.Red()
part.Size = Vector3.new(x,y,z)
part.CFrame = hitposition
part.Material = "Neon"
part.Transparency = 0.5
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and not green then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
green = true
part.BrickColor = BrickColor.Green()
end
end)
wait(0.1)
game.Debris:AddItem(part3,1)
local part4 = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.Red()
part.Size = Vector3.new(x,y,z)
part.CFrame = hitposition
part.Material = "Neon"
part.Transparency = 0.5
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and not green then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
green = true
part.BrickColor = BrickColor.Green()
end
end)
wait(0.1)
game.Debris:AddItem(part4,1)
green = false
end)
local script
local play = game:GetService("Players")
local plr = play.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local rend = game:GetService("RunService")
local rep = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local debri = game:GetService("Debris")
local teams = game:GetService("Teams").killer
plr.Team = teams
local qcd = false
local animator = hum:WaitForChild("Animator")
local hit = script:WaitForChild("attack")
local hitting = animator:LoadAnimation(hit)
local q = script:WaitForChild("q ability")
local locate = animator:LoadAnimation(q)
local debounce = false
local hitbox = rep.remotes:WaitForChild("Event")
local gottagofast = rep.remotes:WaitForChild("goback")
local Comp = require(rep.service.ModuleScript)
local tableUtils = require(rep.service.TableUtils)
local hitpos = {}
local damage = 10
local x = 5
local y = 5
local z = 7
uis.InputBegan:Connect(function(input,gpe)
if gpe then return end
local function gottafast()
hitpos = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-6)
gottagofast:FireServer(hitpos)
end
rend.RenderStepped:Connect(gottafast)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if debounce then return end
hum.WalkSpeed *= 1.5
debounce = true
hitting:Play()
hitbox:FireServer(damage, x, y, z, hitpos)
wait(0.5)
hum.WalkSpeed /= 1.5
wait(0.4)
debounce = false
end
end)
uis.InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.Q then
if debounce then return end
if qcd then return end
hum.WalkSpeed = 0
debounce = true
locate:Play()
for i, Player in pairs(play:GetPlayers()) do
if Player ~= play.LocalPlayer then
local Character = Player.Character
if Character then
if Character:FindFirstChildWhichIsA("Highlight") then
Character:FindFirstChildWhichIsA("Highlight"):Destroy()
end
if Player.Team ~= play.LocalPlayer.Team then
local Highlight = Instance.new("Highlight")
Highlight.FillColor = Color3.new(1)
Highlight.Parent = Character
wait(0.9)
qcd = true
wait(3)
game.Debris:AddItem(Highlight,1)
debounce = false
end
end
end
end
end
end)
local function cooldown()
while qcd == true do
wait(10)
qcd = false
end
end
rend.RenderStepped:Connect(cooldown)