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

Why might this not be working? i Literally have no idea... i'm dumb.

script.Parent.Touched:connect(function()
	game.ReplicatedStorage.WeaponUI.Slot1:Clone().Parent = game.StarterGui.Inventory.TheInv.Items
	script.Disabled = true
end)

4 comments

0

What are the errors

0

Also disabling the script doesnt seem like a good idea, as it will only run once

0

Take a look at my answer to understand  and get an in-depth explain of what went wrong.

0

I resolved my issue, it was a reference error.

5 answers

✓ Accepted answer

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

0

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

0

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

0

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

0

Raccoonyz, actually you can. I tried it before and it works.

0

But idk

0

man you guys are too fast. You always answer it after me

0

But yours is actually pretty good. Good job! :)

0

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

0

didnt work

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