script.Parent.Touched:connect(function()
game.ReplicatedStorage.WeaponUI.Slot1:Clone().Parent = game.StarterGui.Inventory.TheInv.Items
script.Disabled = true
end)
Why might this not be working? i Literally have no idea... i'm dumb.
5 answers
You're trying to alter the StarterGui, which will have no effect on the player's inside of the game.
Instead, you have to get the player from who touched the part.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(character)
if player then
local newUI = game:GetService("ReplicatedStorage").WeaponUI.Slot1:Clone()
newUI.Parent = player:WaitForChild("PlayerGui").Inventory.TheInv.Items
script.Disabled = true
end
end
end)
This will find the player from their character and clone the UI, and put it in the pre-existing one.
Hope this helped!
1 comment
didnt work no errors
I need the errors, but here is me attempting to make it work cause I can't see any errors happening.
script.Parent.Touched:connect(function()
repeat
local WeaponUI = game.ReplicatedStorage.WeaponUI
local Slot1 = WeaponUI.Slot1
local clone = Slot1:Clone()
clone.Parent = game.Players.LocalPlayer.Inventory.TheInv.Items
until clone.Parent = game.Players.LocalPlayer.Inventory.TheInv.Items
end)
Comment if that didn't work what the error is.
1 comment
it didnt work, no error i tried adding PlayerGui to it but still didnt work
Upon trying to modify the User Interface of a Player, you must reference the PlayerGui. StarterGui is a replication container, all of the content stored within is transferred to the Player upon joining. You can view it as similar behaviour to StarterGear and Backpack.
Clone() will return a duplicated Instance of the Object the method is called on. You cannot apply the assign = operator here, as it is merely the same thing as calling script = workspace.
To actively change the location of an Instance is to set it’s Parent property instead.
On a final note, the Touched signal of Instance will fire at anything that has contact, you need to properly filter for the Player to ensure it will only perform actions respectively. As you are aware, Hit.Parent normally corresponds to the Character If touched by a Player, we can use this to ensure it is an avatar rig by confirming the presence of a Humanoid then trying to uplink back to the Player via the Character through the GetPlayerFromCharacter method of Players.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Part = script.Parent
Part.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if (Humanoid) then
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if (Player and Player.PlayerGui) then
local CloneInterface = ReplicatedStorage.WeaponUI.Slot1:Clone()
CloneInterface.Parent = Player.PlayerGui.Inventory.TheInv.Items
end
end
end)
1 comment
sorry man but yours doesnt working and has no errors too.
script.Parent.Touched:connect(function()
local clone = game.ReplicatedStorage.WeaponUI.Slot1:Clone()
clone.Parent = game.StarterGui.Inventory.TheInv.Items
script.Disabled = true
end)
You can't set the parent of a clone and create a clone at the same time.
5 comments
Raccoonyz, actually you can. I tried it before and it works.
But idk
man you guys are too fast. You always answer it after me
But yours is actually pretty good. Good job! :)
didnt work no error
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
-- Makes sure it is a player
game.ReplicatedStorage.WeaponUI.Slot1:Clone().Parent = game.StarterGui.Inventory.TheInv.Items
script.Disabled = true
end
end)
1 comment
didnt work
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
What are the errors
Also disabling the script doesnt seem like a good idea, as it will only run once
Take a look at my answer to understand and get an in-depth explain of what went wrong.
I resolved my issue, it was a reference error.