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

Anyone know how to get a player's folder?

Trying to make a vehicle spawning gui to where if you push a button it will clone a gui from serverstorage into the player who pressed the button's player gui, then once they select a vehicle it will find their position and spawn a vehicle on them.

2 answers

Well yes, since you are doing it with a button(gui) you can keep parenting until get to the parent of the starter gui, since starter gui becomes playergui where its parent is the player folder. Here is an example: Let's say the button is in a screen gui and the screen gui is in the starter gui, you make a script in that button and start it with a variable like so:

local player = script.Parent.Parent.Parent.Parent

And like that you got the player folder

3 comments

0

Really bad example but alright.

0

.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.

0

ok

Basic Info

Firstly, you should be writing your own code to show that you've made an attempt at this

I would instead have the VehicleGui in the StarterGui and simply change its Enabled property rather than perform the cloning but to answer your question...

Examples

Information about Hierarchy

Use RemoteEvents to make button activations affect the server

  1. All ServerScripts in these examples would be in the ServerScriptService
  2. All LocalScripts in these examples would be parented under the button which is clicked / activated.
  3. In my example, I also have 2 RemoteEvents in the ReplicatedStorage named "CloneEvent" and "SpawnEvent" respectively.
  4. The second example requires the car's name to match the text of the TextButton that was activated
  5. The car to clone would be parented under the ServerStorage

Clone a Gui into the Player's PlayerGui

Local Script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("CloneEvent")
local button = script.Parent

button.Activated:Connect(function()
	remote:FireServer()
end)

Simply fire the event when clicked

Server Script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("CloneEvent")
local vgui = game:GetService("ServerStorage"):WaitForChild("VehicleGui")

remote.OnServerEvent:Connect(function(player)
	local pgui = player:WaitForChild("PlayerGui")
	if not pgui:FindFirstChild(vgui.Name) then
		local clone = vgui:Clone()
		clone.Parent = pgui
	end
end)

Check if a "VehicleGui" is already in the PlayerGui, if not, clone it and place it there

Spawn Vehicle at Player's Location

Local Script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("SpawnEvent")
local button = script.Parent

button.Activated:Connect(function()
	remote:FireServer(button.Text)
end)

Fires the remote assuming the selected car is based on a TextButton's text

Server Script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("SpawnEvent")
local SS = game:GetService("ServerStorage")

remote.OnServerEvent:Connect(function(player, car)
	local pgui = player:WaitForChild("PlayerGui")
	local vgui = pgui:FindFirstChild("VehicleGui")
	if vgui then
		vgui:Destroy()
	end
	
	local root = player.Character:WaitForChild("HumanoidRootPart")
	local vehicle = SS:WaitForChild(car):Clone()
	vehicle.Parent = workspace
	vehicle:SetPrimaryPartCFrame(root.CFrame + Vector3.new(0, 0, 0))
end)

First, remove the VehicleGui, then spawn the car to the player's location

SetPrimaryPartCFrame is meant for Models only

The addition of a Vector3 is in case the spawned car should be offset from the player's location by a certain amount

1 comment

0

Cloning the GUI to the player is better if you have server script and want to avoid making remote event just to enable the gui as you can't access it with the server script

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