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

Car GUI working in StarterGUI, but not when using tool?

Asked by 3 years ago

Hello, I am trying to make an rc car game. So I have a tool that opens up a gui for the car. It works in StarterGUI, but for some weird reason the gui doesn't work when I use my tool. Can somebody help? Tool open gui script (local):

local menuClone

script.Parent.Equipped:Connect(function()
    if not game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("OreoMenu") then
        menuClone = script.Parent.OreoMenu:Clone()
        menuClone.Parent = game:GetService("Players").LocalPlayer.PlayerGui
    end
end)

script.Parent.Unequipped:Connect(function()
    pcall(function()
        menuClone:Destroy()
    end)
end)

GUI button script (server):

script.Parent.MouseButton1Click:Connect(function()
    workspace.OreoCar.Shell.Velocity = workspace.OreoCar.Shell.CFrame.LookVector * -100
end)

I placed my gui in the tool

2 answers

Log in to vote
1
Answered by 3 years ago

I see several issues with your code. I'll try to solve these, but the main issue is that you're not using remote events. Remote events allow the client and server to communicate with each other. This is especially true with GUIs. Here's my answer.

Local Script

script.Parent.Equipped:Connect(function()
    local plrGui = game.Players.LocalPlayer.PlayerGui
    if not plrGui:FindFirstChild("OreoGui") then
        local oreoClone = script.Parent.OreoMenu:Clone()
        oreoClone.Parent =  plrGui
        oreoClone.MouseButton1Up:Connect(function()
            game.ReplicatedStorage.RemoteEvent:FireServer()
        end)
    end
end)

script.Parent.Unequipped:Connect(function()
    local plrGui = game.Players.LocalPlayer.PlayerGui
    if plrGui:FindFirstChild("OreoGui") then
        plrGui.OreoGui:Destroy()
    end
end)

Server Script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
    workspace.OreoCar.Shell.Velocity = workspace.OreoCar.Shell.CFrame * -100
end)
Ad
Log in to vote
0
Answered by 3 years ago

Maybe either the GUI has 'Enabled' set to false, or your frame has 'Visible' set to false. Play the game via studio, open the players tab, open your name, then PlayerGui. Click on the car and see if the GUI goes there. If it doesn't, your problem is on something you scripted. If it does, but doesn't show up in your screen, it's maybe because of one of the reasons I said above.

0
No, the problem is that the GUI shows up, but the buttons don't work. They work when I place it in StarterGUI though. squidiskool 208 — 3y

Answer this question