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

This script won’t work and im using a local script, any ideas? (See Description)

Asked by
CedCed6 32
3 years ago
Edited 3 years ago

So I made a gui and I want the gui to appear when someone sits on the VehicleSeat and im using a local script, but it isn’t working. Here’s how the script looked like:

function onSit(humanoid)
    game.Players.LocalPlayer.Character.Humanoid:Connect(function()
        local Gui = game.StarterGui.SpeedGUI
        Gui.Frame.Visible = true
    end
end

Im a beginner at scripting so please help

(Sorry if my grammar is very bad)

1 answer

Log in to vote
0
Answered by 3 years ago

I'm gonna give you an explanation on how to appear, Gui, when the player does something on the server. Since it's a server to client situation you need a Server Script, Remote Event, Local Script. In this example, we have a part in the game ... When the player touches the part a GUI will appear for a couple of seconds and will disappear. So first, create a remote event located in replicated storage. In the local script

local rs = game:GetService("ReplicatedStorage")
local remote = rs.GuiOnChat


remote.OnClientEvent:Connect(function()
    print("Frame Visible")
    script.Parent.Frame.Visible = true
    wait(5)
    script.Parent.Frame.Visible = false

end)

what is happening here is that the local script is waiting for the event to be fired so it makes the GUI appear on the client of the player that touched the part.

Now in the server script located in the part to be touched:

local rs = game:GetService("ReplicatedStorage")
local remote = rs.AppearGui
local debounce = true

script.Parent.Touched:Connect(function(otherPart)
    local char = otherPart.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    if player and debounce then
        debounce = false
        remote:FireClient(player)
        wait(2)
        debounce = true
    end
end)

so when the part is touched, check if its a player, if its a player then fire the event which makes the GUI appear.

0
Tysm! CedCed6 32 — 3y
0
can you replace the part with vehicle seat? CedCed6 32 — 3y
0
yes, vehicle seat has the .Touched event so you can replace the part with the seat Mikael20143 138 — 3y
Ad

Answer this question