Hey there.
I know this has been posted several times, but my script doesn’t seem to be working quite fine and I don’t know why really. I want to create a tool you can use to push away players. The logic is the following:
- A raycast is shoot to wherever the mouse is.
- If there is a player there, add velocity * the localplayer’s look vector.
But what’s wrong here?
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Camera = game:GetService("Workspace").CurrentCamera
local Params = RaycastParams.new()
local Whitelist = { }
for I, Player in pairs (Players:GetPlayers()) do
if Player ~= LocalPlayer then
Whitelist[I] = Player
end
end
Params.FilterDescendantsInstances = { Players } -- Anything you want, for example the player's character, the ray filters through these
Params.FilterType = Enum.RaycastFilterType.Whitelist -- Choose whitelist or blacklist
function RayResult(X, Y)
local UnitRay = Camera:ScreenPointToRay(X, Y)
return game:GetService("Workspace"):Raycast(UnitRay.Origin, UnitRay.Direction * 2, Params) -- 500 studs
end
UIS.InputEnded:Connect(function(Input, GameProcessed)
if not GameProcessed then
if Input.UserInputType == Enum.UserInputType.Touch or Input.UserInputType == Enum.UserInputType.MouseButton1 then
RayResult(Input.Position.X, Input.Position.Y)
print(RayResult(Input.Position.X, Input.Position.Y))
end
end
end)