I’m trying to make a part constantly spawn under my characters feet to stop me from falling so I set the Y value before the loop so that doesn’t change. For some reason the Y value is always set to 0 instead of my position -5. The X and Z loop works as intended
local charPos = Player.Character.HumanoidRootPart
local platform = Instance.new("Part")
platform.Color = Color3.fromRGB(255, 0, 0)
platform.Size = Vector3.new(5,0.2,5)
platform.Parent = workspace
platform.Anchored = true
platform.Position = Vector3.new(nil,charPos.Position.Y - 5,nil)
while ghostmapEnabled == true do
task.wait()
local characterRoot = Player.Character.HumanoidRootPart
platform.Position = Vector3.new(characterRoot.Position.X,nil,characterRoot.Position.Z)
end
Thanks for your response! Yeah I realized that after I posted. I was just hoping nil would be set to whatever the Y value was set to before the loop.
I’ve made some changes using CFrames but I can’t figure out how to keep the Y value of the player from changing and to only change the X and Z values in the loop when I move. With these changes I just fall down.
local charPos = Player.Character.HumanoidRootPart
local platform = Instance.new("Part")
platform.Color = Color3.fromRGB(255, 0, 0)
platform.Size = Vector3.new(5,0.2,5)
platform.Anchored = true
platform.Material = Enum.Material.Neon
platform.CFrame = CFrame.new(charPos.Position.X,charPos.Position.Y-5,charPos.Position.Z)
platform.Parent = workspace
while ghostmapEnabled == true do
task.wait()
local charRoot = Player.Character.HumanoidRootPart
platform.CFrame = charRoot.CFrame * CFrame.new(0,-5,0)
end
When you create a new Vector3, or any other value type using .new, the method has no way of knowing what the previous value was. Try this instead:
local platform = Instance.new("Part")
platform.Color = Color3.fromRGB(255, 0, 0)
platform.Size = Vector3.new(5,0.2,5)
platform.Anchored = true
platform.Material = Enum.Material.Neon
game:GetService("RunService").RenderStepped:Connect(function()
if ghostmapEnabled and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
local root = Player.Character.HumanoidRootPart
platform.CFrame = root.CFrame * CFrame.new(0,-4 - platform.Size.Y / 2,0)
if not platform.Parent then platform.Parent = workspace end
end
end)
Thanks for your quick response! I gave your edits a shot but now my character slowly falls down at a decent pace. Is there any way to spawn the brick under the character then have the loop only update the X and Z positional values?
local platform = Instance.new("Part")
platform.Color = Color3.fromRGB(255, 0, 0)
platform.Size = Vector3.new(5,0.2,5)
platform.Anchored = true
platform.Material = Enum.Material.Neon
local ypos = 0
game:GetService("RunService").RenderStepped:Connect(function()
if ghostmapEnabled and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
local root = Player.Character.HumanoidRootPart
platform.Position = Vector3.new(root.Position.X, ypos, root.Position.Z)
if not platform.Parent then platform.Parent = workspace end
end
end)
Physics is hard sometimes. If you set the position to always under the character, the character will likely fall slowly unless you’re smart with how you code it. I don’t really know how to fix that right now.
local function GhostMapFunc()
local platform = Instance.new("Part")
if ghostmapEnabled then
for _, map in pairs(game.Workspace:GetChildren()) do
if map:IsA("Part") or map:IsA("Model") and not map:FindFirstChild("Humanoid") then
map.Parent = game.Lighting
end
end
local charPos = Player.Character.HumanoidRootPart
platform.Color = Color3.fromRGB(255, 0, 0)
platform.Size = Vector3.new(5,0.2,5)
platform.Anchored = true
platform.Material = Enum.Material.Neon
platform.CFrame = charPos.CFrame * CFrame.new(0, -4, 0)
platform.Parent = workspace
while ghostmapEnabled == true do
task.wait()
local charRoot = Player.Character:WaitForChild("HumanoidRootPart")
platform.CFrame = CFrame.new(charPos.CFrame.X, platform.CFrame.Y, charPos.CFrame.Z)
end
elseif not ghostmapEnabled then
for _, map in pairs(game.Lighting:GetChildren()) do
if map:IsA("Part") or map:IsA("Model") and not map:FindFirstChild("Humanoid") then
map.Parent = game.Workspace
end
end
platform:Destroy()
end
end