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

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

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

✓ Accepted answer

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.

3 comments

0

Tysm!

0

can you replace the part with vehicle seat?

0

yes, vehicle seat has the .Touched event so you can replace the part with the seat

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