Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Anyone know how to get a player's folder?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

0
Really bad example but alright. VitroxVox 884 — 4y
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. royaltoe 5144 — 4y
0
ok YahiaElramal_77 26 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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 karlo_tr10 1233 — 4y

Answer this question