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

My script works on Play Solo but not Online?

I've tried changing it from a regular script to a Localscript but that still does absolutely nothing there are no errors in the Dev Console

the script is for a ClickDetector which is interacting with a Gui (Inventory Gui picking up items)

its being stupid and my Online game won't work for crap!

The Game

Here's the script

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    script.Parent:FindFirstChild("PlrName").Value = plr.Name
local plrgui = game.Players:FindFirstChild(script.Parent:FindFirstChild("PlrName").Value).PlayerGui

if plrgui.Inventory.Frame.Slot1.Item.Value == "" then
plrgui.Inventory.Frame.Slot1.Item.Value = script.Parent.Name
script.Parent:Destroy()
elseif
plrgui.Inventory.Frame.Slot2.Item.Value == "" then
plrgui.Inventory.Frame.Slot2.Item.Value = script.Parent.Name
script.Parent:Destroy()
elseif
plrgui.Inventory.Frame.Slot3.Item.Value == "" then
plrgui.Inventory.Frame.Slot3.Item.Value = script.Parent.Name
script.Parent:Destroy()
elseif
plrgui.Inventory.Frame.Slot4.Item.Value == "" then
plrgui.Inventory.Frame.Slot4.Item.Value = script.Parent.Name
script.Parent:Destroy()
elseif
plrgui.Inventory.Frame.Slot5.Item.Value == "" then
plrgui.Inventory.Frame.Slot5.Item.Value = script.Parent.Name
script.Parent:Destroy()
elseif
plrgui.Inventory.Frame.Slot6.Item.Value == "" then
plrgui.Inventory.Frame.Slot6.Item.Value = script.Parent.Name
script.Parent:Destroy()
end
end)

1 answer

✓ Accepted answer
local Obj = script.Parent

Obj.ClickDetector.MouseClick:connect(function(plr)
	Obj:FindFirstChild('PlrName').Value = plr.Name
	local PlrGUI = game.Players:FindFirstChild(plr.Name).PlayerGui
	if PlrGUI then
		local MaxSlots = {1,2,3,4,5,6}
		for _, v in pairs(MaxSlots) do
			local vx = PlrGUI.Inventory.Frame:FindFirstChild("Slot" .. tostring(v))
			if vx and vx.Item.Value == "" then
				vx.Item.Value = Obj.Name
				Obj:Destroy()
				break
			end
		end
	end
end)

What that does is checks if the part is clicked if so then it adds the player's name to the PlrName then it loops through the Inventory and checks the slots, in the MaxSlots table you can add how many slots you want, I just made it six because I see in your code its six.

2 comments

0

dude I mean this script is great and efficient but still doesn't help my issue at all...

0

lol Actually I found out the issue it was the GUI none of the scripts were local they were all regular sorry I was up at like 1:00 AM working on my game and didn't even notice that

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