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

Help with CFraming a whole model relative to the player?

print("Sanji02 is a cool guy")
Player = game.Players.LocalPlayer
char = Player.Character
Mouse = Player:GetMouse()


function onKeyDown(key)
	key = key:lower()
	if key == "e" then
		if game.Workspace:findFirstChild("Rashomon") then
			return end
		local Rashomon = game.ServerStorage.Rashomon:Clone()
		Rashomon.Parent = game.Workspace
		local Rashokids = Rashomon:GetChildren()
		Rashokids.CanCollide = true
		Rashokids.Anchored = true
		local CoolLighting = Instance.new("Humanoid")
		CoolLighting.Parent = Rashomon
		Rashokids.CFrame = char.Torso.CFrame *CFrame.new(0, 0, -5)
	end
end

Mouse.KeyDown:connect(onKeyDown)

The script is supposed to spawn a wall that is a model from ServerStorage infront of the player. The script only spawns the wall. But the wall won't spawn infront of the player? Any help?

1 answer

The reason why it doesn't work is because you didn't specified which Part of the Model to take at the lines 15,16 and 19. You must create a loop with the "for" to do that. So at the end, the script will be like this:

print("Sanji02 is a cool guy")
Player = game.Players.LocalPlayer
char = Player.Character
Mouse = Player:GetMouse()


function onKeyDown(key)
    key = key:lower()
    if key == "e" then
        if game.Workspace:findFirstChild("Rashomon") then
            return end
        local Rashomon = game.ServerStorage.Rashomon:Clone()
        Rashomon.Parent = game.Workspace
        local Rashokids = Rashomon:GetChildren()
		for i = 1,#Rashokids do -- Creates a loop with the number of Part inside the model to know which part will be selected.
			if Rashokids[i].ClassName == "Part" then -- Just added this because all parts inside the model may not be a part.
				Rashokids[i].CanCollide = true
       			Rashokids[i].Anchored = true
				Rashokids[i].CFrame = char.Torso.CFrame *CFrame.new(0, 0, -5)
			end
		end
        local CoolLighting = Instance.new("Humanoid")
        CoolLighting.Parent = Rashomon
    end
end

Mouse.KeyDown:connect(onKeyDown)

I hope I answered your question.

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