Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Part isn't appearing where I tell it to? CFrame and Position won't work?

I've got a script that puts a part with a cloud mesh under the player's foot when they press Q. In test servers, and in the real game, the part will glitch and show up above, or below the player. EXAMPLE

Any idea why this could be happening? Is it an FE related issue? I've tried using Position and CFrame, and it doesn't help.

Local Script:

wait(2)
local Player = game.Players.LocalPlayer
local char = Player.Character
local mouse = Player:GetMouse()
local stam = Player.Stats.Stamina

Skilluse = 0
UsedMoon = 0

function MoonWalk(key)
	local Key = key:lower()
	if key == "q" and Skilluse == 0 and UsedMoon == 0 and stam.Value >= 100 and Player.Stats.StaminaXPMAX.Value >= 50  then
		Skilluse = 1 UsedMoon = 1
		script.MoonWalkEvent:FireServer()
		wait(0.5)
		Skilluse = 0 UsedMoon = 0
	end
end


function OnEquipped(mouse) 
	mouse.KeyDown:Connect(MoonWalk)
	Player.PlayerGui.MainHUD.SixPowerSkills.Visible = true
end 

script.Parent.Unequipped:Connect(function(mouse)
	Player.PlayerGui.MainHUD.SixPowerSkills.Visible = false
end)
script.Parent.Equipped:Connect(OnEquipped)

Server Script:

function MoonWalk(Player)
	local stam = Player.Stats.Stamina
	Player.Stats.StaminaXP.Value = Player.Stats.StaminaXP.Value + 5
	stam.Value = stam.Value - 100
	local Cloud = script.Parent.Cloud:Clone()
	Cloud.Parent = Player.Character
	Cloud.CFrame = Player.Character:FindFirstChild("Right Leg").CFrame
	Cloud.Position = Player.Character:FindFirstChild("Right Leg").Position
	game.ServerScriptService.SuperFastRemove:Clone().Parent = Cloud
	local Grow = script.Parent.CloudGrow:Clone()
	Grow.Parent = Cloud
	Grow.Disabled = false
	local BV = Instance.new("BodyVelocity")
	   BV.maxForce = Vector3.new(math.huge, math.huge, math.huge)
	   BV.velocity = Vector3.new(0,30,0)
	   BV.Parent = Player.Character:FindFirstChild("Torso")
	Player.Character.Torso.Geppo:Play()
	   game.ServerScriptService["ULTRA REMOVE"]:Clone().Parent = BV
end

script.Parent.MoonWalkEvent.OnServerEvent:Connect(MoonWalk)

Thanks for reading.

1 answer

You don't have to set both CFrame and Position of a Part because both do different things.

CFrame is a data type that is both the Position of the Part and the Orientation (How it's rotated) of the Part.

Position is a Vector3 (Which are the X,Y,Z values in a 3D Plane) that is basically the location of a part.

You should use CFrame because you can use a Vector3 to change the CFrame. So, instead of positioning it on the right leg, we'll first CFrame it on the Torso then use a Vector3 to offset it 2 studs below which is basically in between the legs.

function MoonWalk(Player)

--This part bugged me out so I changed it
    Player.Stats.Stamina.Value = stam.Value - 100 
    Player.Stats.StaminaXP.Value = Player.Stats.StaminaXP.Value + 5

    local Cloud = script.Parent.Cloud:Clone()
    Cloud.Parent = Player.Character

--Offset 2 studs down from the Torso's CFrame to get the new pos of the cloud part.
    Cloud.CFrame = Player.Character:FindFirstChild("Torso").CFrame + Vector3.new(0,-2,0)


--You should define "ServerScriptService" outside of this function. At the top preferably.
    game.ServerScriptService.SuperFastRemove:Clone().Parent = Cloud
    local Grow = script.Parent.CloudGrow:Clone()
    Grow.Parent = Cloud
    Grow.Disabled = false

    local BV = Instance.new("BodyVelocity")
       BV.maxForce = Vector3.new(math.huge, math.huge, math.huge)
       BV.velocity = Vector3.new(0,30,0)
       BV.Parent = Player.Character:FindFirstChild("Torso")
    Player.Character.Torso.Geppo:Play()

--Again, define "ServerScriptService" and change this. Makes it look readable
       game.ServerScriptService["ULTRA REMOVE"]:Clone().Parent = BV
end

script.Parent.MoonWalkEvent.OnServerEvent:Connect(MoonWalk)

The offset might not be where you want it. If you want it lower then change the -2 to like -2.5 and that should be right below the legs

1 comment

0

That method produces the same effect as before. Doesn't fix anything, it's just right above the head rather than above and to the right a little bit

This discussion is preserved as it was. New answers, comments, and votes are closed.