alright so i’ve been trying to make a fps game in which you can choose a loadout and change it. my idea for changing the loadout is just parenting the tools a player has in his backpack to replicatedstorage, but it just doesn’t work. here’s the script and where it is
local AK = game.StarterPack:FindFirstChild("AK101")
script.Parent.MouseButton1Click:Connect(function()
game.StarterGui.GunChoose.GunChooseFrame.Visible = true
if AK then
AK.Parent = game.ReplicatedStorage
end
end)
the “button” textbutton is the button that was suppost to parent every tool to the replicatedstorage
Modifying game.StarterGui does not immediately replicate to a client it only does once their character resets. To modify a players current ui you have to edit PlayerObject.PlayerGui instead of game.StarterGui
Its the same issue as before. game.StarterPack isnt actually what is in the players backpack currently its just a template for when the character loads. Instead use Player.Backpack
Alright one more thing. so if i do Player.Backpack, do i also do “FindFirstChild” because im planning on adding more guns. so the player’s wont always have that exact gun.
Have a table filled with all the possible guns and loop through the table checking if the player has the corresponding gun which then you parent it to replicated storage
while wait(1) do
local Player = game.Players.LocalPlayer
local plr = game:GetService("Players")
local gun1 = Player.Backpack:FindFirstChild("AK101")
local gun2 = Player.Backpack:FindFirstChild("GLOCK17")
local guns = {gun1, gun2}
if Player.PlayerGui.GunChoose.GunChooseFrame.Visible == true then
guns.Parent = game.ReplicatedStorage
end
end
script.Parent.MouseButton1Click:Connect(function(player)
local AK = player.Backpack:FindFirstChild("AK101")
player.PlayerGui.GunChoose.GunChooseFrame.Visible = true
if AK then
AK.Parent = game.ReplicatedStorage
end
end)
if you want more guns just make a button for every gun
What I would suggest (This is also how I got through it) is having the local script fire a Remote Event and having a Server Script handle what that Event does (Cloning the tool to the player’s backpack)
I should mention too that instead of having the tools in ReplicatedStorage they should be in ServerStorage. You can’t make local scripts reference objects in ServerStorage as only the Server can see them which is why making the Event and Server Script is necessary.