So I'm trying to do a spell that pushes all players within the vicinity of the character away, but the issue is that my player is being pushed as well.. how can I fix this?
This is my ServerScript.
ReplicatedStorage = game:GetService("ReplicatedStorage")
remoteEvent = ReplicatedStorage:WaitForChild("push")
function onCreatePart(hey, period, boo)
local Players = game:GetService("Players")
local character = hey.Character
if not character or not character.Parent then
character = hey.CharacterAdded:Wait()
end
local radius = 12
local pushbackDistance = 20
local pushbackHeight = 10
local part = boo.HumanoidRootPart
local player = not game.Players.LocalPlayer
local debounce = true
while wait(0.1) do
local partPos = part.Position
local currentRadius = player:DistanceFromCharacter(part.Position)
if debounce and radius > 0 and currentRadius <= radius then
if player.Character then
local head = player.Character:FindFirstChild("Head")
if head then
local headPos = head.Position
debounce = false
local bp = Instance.new("BodyPosition")
bp.D = 50
bp.Position = (CFrame.new(partPos, Vector3.new(headPos.X, partPos.Y, headPos.Z)) * CFrame.new(0,0,-pushbackDistance)).p + Vector3.new(0,pushbackHeight,0)
bp.Parent = head
wait(0.5)
bp:Destroy()
debounce = true
end
end
end
end
end
remoteEvent.OnServerEvent:Connect(onCreatePart)
This is my LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local test = true
local remoteEvent = ReplicatedStorage:WaitForChild("push")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if test == true then
if key == "x" and player.TeamColor == BrickColor.new("Mulberry") then
local period = player
local boo = player.Character
remoteEvent:FireServer(period, boo)
test = false
wait(15)
test = true
end
end
end)
I also have a RemoteEvent in ReplicatedStorage called "push".
