i making player char going 30 studts and when it moces 30 studs it can go into the part heres a video about it:
here the move script
ReplicatedStorage.Events.RemoteEvents.MoveChar.OnServerEvent:Connect(function(plr)
local character = plr.Character or plr.CharacterAdded:Wait()
if character then
local position = character.HumanoidRootPart.Position
local direction = character.HumanoidRootPart.CFrame.LookVector
local targetPosition = position + (direction * 30)
character.HumanoidRootPart.CFrame = CFrame.new(targetPosition)
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Okay, I guess. I hope this work since I literally haven’t tested it yet :
local character = plr.Character or plr.CharacterAdded:Wait()
if character then
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character:GetChildren()}
local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30)
if Raycast ~= nil then
character.HumanoidRootPart.Position = Raycast.Position
else
character.HumanoidRootPart.Position = character.HumanoidRootPart.CFrame.LookVector * 30
end
end
local character = plr.Character or plr.CharacterAdded:Wait()
if character then
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character:GetChildren()}
local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30)
if Raycast ~= nil then
character:PivotTo(CFrame.new(Raycast.Position))
else
character:PivotTo(CFrame.new(HumanoidRootPart.CFrame.LookVector * 30))
end
end
local character = plr.Character or plr.CharacterAdded:Wait()
if character then
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character:GetChildren()}
local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30)
if Raycast ~= nil then
character:PivotTo(CFrame.new(Raycast.Position))
else
character:PivotTo(HumanoidRootPart.CFrame * CFrame.new(30,0,0))
end
end
What you’re doing is teleporting the player, obviously this will cause issues.
Here is what you could do:
RayCast in front of the player, to see until when the player would reach a part, then move them to the end of the RayCast instead of 30 studs forwards.
Push the player forwards with BodyVelocity, BodyForce though these 2 are deprecated. So instead use LinearVelocity.
Also your script is complicating something simple:
local position = character.HumanoidRootPart.Position
local direction = character.HumanoidRootPart.CFrame.LookVector
local targetPosition = position + (direction * 30)
character.HumanoidRootPart.CFrame = CFrame.new(targetPosition)
Can be replaced with:
local root = character:FindFirstChild("HumanoidRootPart")
root.CFrame = root.CFrame * CFrame.new(Vector3.new(0, 0, 30))
-- make sure this is the correct direction, it's either the X or Z direction
-- and also make sure if it has to be negative or not.
Honestly raycasting is not my expertise. Though if I am right the issue you’re currently facing has to do with you moving the player incorrectly with
CFrame.new(Vector3.new(30, 0, 0)
Instead of
CFrame.new(Vector3.new(0, 0, 30))
Also
would not work correctly because it’s an array inside an array, instead:
local character = plr.Character or plr.CharacterAdded:Wait()
if character then
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character}
local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30, raycastParams)
if Raycast ~= nil then
character:PivotTo(CFrame.new(Raycast.Position))
else
character:PivotTo(HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,30)))
end
end
if I am not mistaken this should work correctly.
Note, make sure to mess around with the CFrame being correctly aimed, either X, -X, Z or -Z.