--Variables--
local Brick = script.Parent
--End--
--Code--
local function PlayerTouched(Part)
print("Touched")
end
end
Brick.Touched:connect(PlayerTouched)
This is the code to fling a player, but first you actually have to get the character. Let me know if you do not know how to do that!
--Variables--
local Brick = script.Parent
--End--
--Code--
local function PlayerTouched(Part)
print("Touched")
end
end
Brick.Touched:connect(PlayerTouched)
To get the character you can check to see if the part is a child of the character.
local function GetCharFromPart(part)
if part.Parent:FindFirstChild("Humanoid") ~= nil then
return part.Parent
end
if part.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
return part.Parent.Parent -- In case a hat touches the part.
end
end
local function PlayerTouched(Part)
local character = GetCharFromPart(Part)
end
Oh, and if you want to fling the player, you need to set the network owner all character parts to the server.
local function SetCharacterNetworkOwnership(character, owner)
for _, obj in pairs(character:GetChildren()) do
if obj:IsA("BasePart") then
obj:SetNetworkOwner(owner)
end
end
end
local function GetCharFromPart(part)
if part.Parent:FindFirstChild("Humanoid") ~= nil then
return part.Parent
end
if part.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
return part.Parent.Parent -- In case a hat touches the part.
end
end
local function PlayerTouched(Part)
local character = GetCharFromPart(Part)
if character == nil then
return
end
SetCharacterNetworkOwnership(character, nil)
character.UpperTorso.Velocity = -script.Parent.CFrame.LookVector * 1000 -- Should fling the player in the opposite direction.
end
So all the replies have been giving some things that I’ve never seen but here’s how I personally would go about it.
--# variables
local Brick = script.Parent
local players = {} -- creating a table of all players who touch the part since one touch fires the event a bunch of times
local connection
--# functions
Brick.Touched:Connect(function(TouchedPart)
if TouchedPart.Parent:FindFirstChildOfClass("Humanoid") then -- making sure it is a humanoid then
local character = TouchedPart.Parent
if not character then return end
if table.find(players, character) then return end -- making sure they only touch once
table.insert(players, character)
local BodyVelocity = Instance.new("BodyVelocity") -- using bodyVelocity to throw the player
BodyVelocity.Velocity = CFrame.new(TouchedPart.Position,character.PrimaryPart.Position).LookVector * 1000 -- this line makes a force that moves against the part, you can change the 100 to any number to modify the strength of the push
BodyVelocity.Parent = character.PrimaryPart
-- add your ragdoll script here
wait(0.5)
BodyVelocity:Destroy() -- you have to destroy it or they might go on forever
-- stop ragdoll here
table.clear(players) -- removing the player so they can get pushed if they touch it again
end
end)
you might have to modify this bc i didn’t test it but you get the idea, reply if you have questions
local debounce = false
script.Parent.Touched:Connect(function(hit)
local Hit_Character = hit.Parent:FindFirstChild("Humanoid").Parent or hit.Parent.Parent:FindFirstChild("Humanoid").Parent
if debounce == false then debounce = true
local bv = Instance.new("BodyVelocity")
local offset = Vector3.new()
bv.Parent = (Hit_Character.LowerTorso)
bv.MaxForce = Vector3.new(100000,100000,100000) -- can mess with this or the 80's
bv.Velocity = (Hit_Character.Head.CFrame.LookVector * -80)
+ (Hit_Character.Head.CFrame.UpVector * 80)
wait(0.01) bv:Destroy()
debounce = false
end wait(1)
end)
May want to check for Torso vs LowerTorso for the two types of player bodies.
Bad idea, that’ll create huge times between pressing a movement key and your character actually moving, instead just apply the velocity inside a local script.