What the Scripts on the bottom are supposed to do, when you sit down on the seat (Scripts and gui are in it) a Text pops up on your screen about the car capacity which the max is 8. BUT using the scripts below keeps making errors. I need help? i have screen shots. What it keeps doing is the Text pops up, But the Message Doesnt. (mainly about the 2nd script) i have a numbervalue in workspace named PlayersInCar.
Error Screenshot Seat Stuff Screenshot
Script in seat:
local gui = script.Parent:FindFirstChild("ScreenGui") script.Parent.Touched:Connect(function(hit) if hit.Parent ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent:FindFirstChild("Humanoid") ~= nil then hit.Parent.Humanoid.Seated:Connect(function(active, seat) if player ~= nil then if active == true and seat == script.Parent then if player.PlayerGui:FindFirstChild("ScreenGui") == nil then gui:Clone().Parent = player.PlayerGui game.Workspace.Value.Value = game.Workspace.Value.Value + 1 end elseif active ~= true and seat ~= script.Parent then if player.PlayerGui:FindFirstChild("ScreenGui") ~= nil then player.PlayerGui:FindFirstChild("ScreenGui"):Destroy() end end end end) end end end)
Script in Text Label:
local number = game.Workspace.PlayersInCar script.Parent.Text = "Car Capacity: "..number.."/8" wait(1) if number == 8 then game.Workspace.TeleportPad.Script.Disabled = true game.Workspace.TeleportPad.CanCollide = true else game.Workspace.TeleportPad.Disabled = false game.Workspace.TeleportPad.CanCollide = false end
Improvements
Use workspace
instead of game.Workspace
Use WaitForChild()
to make sure an instance exists before using it
Use GetService()
for the Players
Service
Use the PlayerAdded
function to obtain the player instead of the Touched event of the seat
Issues
Your local variable "number" is the instance "PlayersInCar" not the Value
(a property of the instance)
The workspace.Value
doesnt exist as you need to use the name of the object, not its class
Important Notes
Make "PlayersInCar" an IntValue
instead of a NumberValue
since youre using integers and dont want a float
(your numbers may not match 8 exactly with the NumberValue)
Below, I've made the two scripts a single script, place it under the Seat
Revised ServerScript
local par = script.Parent local gui = par:WaitForChild("ScreenGui") local seated = workspace:WaitForChild("PlayersInCar") local teleport = workspace:WaitForChild("TeleportPad") local tscript = teleport:WaitForChild("Script") game:GetService("Players").PlayerAdded:Connect(function(player) local pgui = player:WaitForChild("PlayerGui") player.CharacterAdded:Connect(function(character) local human = character:WaitForChild("Humanoid") human.Seated:Connect(function(sitting, seat) if sitting == true and seat == par then if not pgui:FindFirstChild("ScreenGui") then local clone = gui:Clone() clone.Parent = pgui seated.Value = seated.Value + 1 end else if seated.Value > 0 then seated.Value = seated.Value - 1 end if pgui:FindFirstChild("ScreenGui") then pgui:WaitForChild("ScreenGui"):Destroy() end end end) end) end) seated:GetPropertyChangedSignal("Value"):Connect(function() for index, player in pairs(game:GetService("Players"):GetPlayers()) do local pgui = player:WaitForChild("PlayerGui") if pgui:FindFirstChild("ScreenGui") then local label = pgui:WaitForChild("ScreenGui"):WaitForChild("TextLabel") label.Text = "Car Capacity: "..seated.Value.."/8" end end wait(1) if seated.Value == 8 then tscript.Disabled = true teleport.CanCollide = true else tscript.Disabled = false teleport.CanCollide = false end end)