Hello So im having a problem with an Cloning ItemFrame to Inv Gui The thing i wanna do is Mouse1 clicked on the part then it clones the ItemFrame {ImageLabe} to inventory Gui So i can see it. script
local player = game:GetService("Players").LocalPlayer
local ui = game.ReplicatedStorage.ItemFrame.BottleOfMilk
local newui = ui:Clone()
function onClicked(player)
newui.Parent = player.PlayerGui.Main.Inv.inv
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked) why it does not work?
There are two things wrong here:
PlayerGui
via the server. Unless your game is in Experimental Mode, you won't be able to pull this off.player
. This should be the player who clicked the ClickDetector as a parameter in the function onClicked
.One solution is to relocate the script to StarterGui and make it a local script. That would look like this:
local ui = game:GetService("ReplicatedStorage").ItemFrame.BottleOfMilk local newui = ui:Clone() local function onClicked(player) newui.Parent = player.PlayerGui.Main.Inv.inv end workspace.Part.ClickDetector.MouseClick:Connect(onClicked)
The other solution is to use RemoteEvents like so.
Server Script in the Part containing the ClickDetector:
local event = game:GetService("ReplicatedStorage"):WaitForChild("UIEvent") script.Parent.ClickDetector.MouseClick:Connect(function() event:FireClient() end)
Local Script in StarterGui:
local event = game:GetService("ReplicatedStorage"):WaitForChild("UIEvent") local ui = game:GetService("ReplicatedStorage").ItemFrame.BottleOfMilk local newui = ui:Clone() event.OnClientEvent:Connect(function(player) newui.Parent = player.PlayerGui.Main.Inv.inv end)