What do you want to achieve?
I want a GUI that can only be seen by the driver of a car when the car hits a part with a hit event.
What is the issue?
My current problem is that the passengers of the car also see the GUI when you hit the touch event part.
What solutions have you tried so far?
I have found a solution on the internet that allows you to create a function when someone gets in the driver seat. The problem is that I don’t know how to handle it with a hit event. This is the code:
seat.ChildAdded:connect(function(seatWeld)
if seatWeld.ClassName == "Weld" and seatWeld.Name == "SeatWeld" then
local player = game.Players:GetPlayerFromCharacter(seatWeld.Part1.Parent)
end
end)
My current hit script is this:
GUI = script.Parent.PaintGUI
script.Parent.Touched:connect(function(hit)
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
local Play = game.Players[hit.Parent.Name]
if Play.Character.Humanoid.Sit == true then
if Play:FindFirstChild("PlayerGui") and not Play.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = Play.PlayerGui
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local car = game.Workspace["car"..plr.Name.."1"]
wait(2)
end
end
end
end)
Btw it is a script for a car garage where you can paint your car to different colors.
Every seat has an event called Touched
You can basically use it to detect a player that has touched the sit.
Here is a small example
local debounce = false
Seat.Touched:Connect(function(hit)
if debounce == true then return end
--getting the humanoid
local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
if not hum then return end -- checking if it didn't find the humanoid
if hum.Sit == true then --every humanoid has a property called Sit, which tells if the user is sat or not
-- do your code
game.Players:GetPlayerFromCharacter(hum.Parent).PlayerGui.GUI.Enabled = true --enabling the gui for the player
end
wait(0.6) -- small cooldown
debounce = false
end)
That works indeed, but the problem is that I can’t just name the local seat, because it first looks at who owns the car. In addition, it needs the local plr. I named that local plr together with the hit argument.
So now it can’t define the hit.
GUI = script.Parent.PaintGUI
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local car = game.Workspace["car"..plr.Name.."1"]
local Seat = car.DriveSeat
local debounce = false
Seat.Touched:Connect(function(hit)
if debounce == true then return end
--getting the humanoid
local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
if not hum then return end -- checking if it didn't find the humanoid
if hum.Sit == true then --every humanoid has a property called Sit, which tells if the user is sat or not
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
local Play = game.Players[hit.Parent.Name]
if Play.Character.Humanoid.Sit == true then
if Play:FindFirstChild("PlayerGui") and not Play.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = Play.PlayerGui
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local car = game.Workspace["car"..plr.Name.."1"]
wait(2)
local Deur = game.Workspace.Deurtje
Deur.Transparency = 0
Deur.CanCollide = true
local L = Instance.new("PointLight", game.Workspace.Licht1)
end
end
end
game.Players:GetPlayerFromCharacter(hum.Parent).PlayerGui.GUI.Enabled = true --enabling the gui for the player
end
wait(0.6) -- small cooldown
debounce = false
end)
Do you have a solution for this @Wqund ?
(Thank you for thinking along)