#the first button to appear in this frame will never work

4 messages · Page 1 of 1 (latest)

magic loom
#

i have 2 guis that only i have in my game
it just spawns either npcs or models in their respective locations
there is a localscript, script and a remote event inside the frame that has the scrollingframe that will house all of the added buttons
the localscript is in charge of adding as many buttons as there are npcs in a folder in replicated storage, it also fires the remote event with the player who fired it and the buttons name incase a button is clicked, then the script will check if it can find an instance in the folder that has the name name as the buttons name, then it will clone it, bring it to the workspace and place it infront of the player who clicked
now, the first button to be added will never work, while the others do
the first button is always different as the script never seems to add each button at the same place every time as you can see in the attached images

#

I will provide both scripts
Here is the local script

local scroll = script.Parent.ScrollingFrame
local template = scroll.Template
local tools = game.ReplicatedStorage.MobsStorage
task.wait(1)
for i, v in pairs(tools:GetChildren()) do
    task.wait(0.1)
    local button = template:Clone()
    button.Parent = scroll
    template.Name = v.Name
    template.Text = v.Name
    template.Visible = true
    button.MouseButton1Click:Connect(function()
        local selected = button.Name
        script.Parent.RemoteEvent:FireServer(selected)
    end)
end
#

and the server script

local tools = game.ReplicatedStorage.MobsStorage
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, selected)
    local tool = tools:FindFirstChild(selected):Clone()
    tool.Parent = workspace.Mobs
    if selected == "GiantNPC" then
        tool.PrimaryPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0,0, -50)
    elseif selected == "AttackingNPC" then
        tool.PrimaryPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0,0, -12)
    else
        tool.PrimaryPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0,0, -6)
    end
    
end)
#

Here is what it looks like in the explorer