So I have a script to spawn a block infront of me but it doesnt seem to always be infront
When it is not anchored then it works most of the time but when you become anchored the part is placed in a position thats not infront of the character. I would like to know how I would fix this?
Server script
local frozen = false
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
if frozen == false then
frozen = true
local part = Instance.new("Part",workspace)
part.Anchored = true
part.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.LookVector * 3
part.CanCollide = false
player.Character.HumanoidRootPart.Anchored = true
player.Character.Humanoid.PlatformStand = true
else
frozen = false
player.Character.HumanoidRootPart.Anchored = false
player.Character.Humanoid.PlatformStand = false
end
end)
Local script
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage.RemoteEvent
uis.InputBegan:Connect(function(input,istyping)
if not istyping then
if input.KeyCode == Enum.KeyCode.E then
event:FireServer()
end
end
end)
infront of the player.
It doesnt work properly when players move at any point. For example if I jump its going to be below the player and if I move the part will be inside of the player but if the player isn’t anchored when this happens it’s perfectly fine.
I am testing the scripts in a project file now, and I don’t see what your problem is? It is instancing a part infront of the player, which… is what you want. Correct me if I am wrong
They are minor optimisation changes, which I would highly recommend you keep and use in the future. Regarding the moving around situation: this part was created whilst jumping in the air (it looks like it should be in the correct placement, for when I was jumping in the air)
Please try and go into more detail about what the actual problem is, seeming as I am failing to replicate it whilst using the same scripts.
Were you anchored in place? That’s what the script does. I said it kind of works perfectly fine if you don’t use anchor but I kind of want to be able to freeze a character in place.
I understand what you mean now, thanks, however I have absolutely no explanation for why this is happening?? It is so weird.
I am going to try and investigate what the problem is, and when I get a solution, I will post it right here.
I have no clue to why this wouldn’t work. Anyone else want to give it a shot?
I found while testing that this is because of a server and client disagreement. Test and jump and press E so it looks like the part is not in front of the player. Then switch to server view.
Theoretically, if your ping was 0 then this wouldn’t happen.
The placement of the part does look correct to other players on the server. technically nothing is wrong
So the problem is because the client takes too long to send the position of HumanoidRootPart to the server and there is no solution. Maybe in 8 years when we all have extremely fast 6G internet then this will be fixed.