Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Please help my scripts work on Play Solo but not Online localscript or Regular script?

Asked by
Prioxis 673 Moderation Voter
10 years ago

My Inventory system which allows users to pick up items off the ground (items use a clickdetector system) but if I made the items script that allows them to pick up the item localscript or regular script it still doesn't work online its confusing and annoying me because I need a decent public release for my game

My game

Item script

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)

The script that changes the Inventory slot to the item name

script.Parent.MouseButton1Down:connect(function(clicked)
if  script.Parent.Parent.Parent.Slot1Item.Visible == true then
script.Parent.Parent.Parent.Slot1Item.Visible = false
else
script.Parent.Parent.Parent.Slot1Item.Visible = true    
end
end)

1 answer

Log in to vote
0
Answered by 9 years ago

It's because in Play Solo, everything's happening on your client, whereas if you're actually playing the game, some of it's on the server. And as everybody learns the hard way, it's really challenging to get a script on the server to do something on a client, and vice-versa.

Someone linked me to a great page on the wiki for this. http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial

In your case, a script in Workspace can't directly make things happen in a gui, since as previously stated, clients and servers don't mix well. I suggest keeping everything roughly the same, but use RemoteEvents and RemoteFunctions to get the job done. If you read the wiki article, it should explain it better than I can.

Ad

Answer this question