I have this plane and the gui with all the infos resets when the player leaves the vehicle.
Not sure why this is happening. Here is the short script that gives the player the gui when they sit in the seat:
newgui = script.Planegui
local char = nil
local name = nil
script.Parent.ChildAdded:connect(function(child)
if child:IsA("Weld") and child.Name == "SeatWeld" then
char = child.Part1.Parent
name = char.Name
if game.Players:FindFirstChild(name) then
local player = game.Players:FindFirstChild(name)
newgui.Parent = player.PlayerGui
newgui.Planescript.Disabled = false
end
end
end)
script.Parent.ChildRemoved:connect(function(child)
if child:IsA("Weld") and child.Name == "SeatWeld" then
local db = false
game.ReplicatedStorage.Checker.OnServerEvent:Connect(function(player,bodykit)
if not db then
db = true
game.ReplicatedStorage.Checker:FireClient(player, bodykit)
db = false
end
end)
newgui.Parent = nil
wait()
script.Parent.BodyGyro.MaxTorque = Vector3.new(0,0,0)
script.Parent.BodyVelocity.MaxForce = Vector3.new(0,0,0)
end
end)
The gui data does not reset as far as i know, i forgot to put this in the video but lets say we had 24 bombs before we jumped out of the plane, and when we re-enter it, it will read 30. If we drop another bomb, the bar will say 23 bombs. so the data is saving, but not the gui.
Understood. Where is the GUI itself updated to show that data too? Is it the same script that actually drops the bomb, or is there another script, maybe client sided, that does that?
If the localscript changes the GUI then the server’s version of it (the one you’re parenting around the place) will not have those changes. It’s good to use a localscript as the update will be instantaneous so keep it a localscript.
Perhaps you want to perform some sort of synchronisation so that the initial values on the GUI match whatever the current data for the plane is as part of your parenting script, that way they don’t have to wait for the first bomb or fuel usage to see the change. Or as part of the localscript, you initialise the GUI values to what they are supposed to be from the plane data. Either option should work fine.
Instead you could set a value of all the objects in you’re vehicle(Health, Bombs, etc) and when they leave the vehicle you could set it to whatever stats they have and when they get back into the vehicle you could get the stats from the values.
What do u mean by that?, this is what you should do.
Make a value of all the stats in you’re vehicle and place them wherever.
In you’re script make a variable, you could call it IfNew.
In the script you could say:
local IfNew = false
local Health = script.Value.Health -- Example
-- When the player sits
Vehicle.Sat:Connect(function() -- change this to say when the player has sat in the vehicle
if IfNew == false then
print("Player has not sat in this vehicle before!") -- Checking if the player hasn't sat in the vehicle
-- in this section you could say whatever you want to do when the player sat down, Set normal stats
else
print("Player isn't new to this vehicle, Settings stats...")
GUI.Health.Text = Health
IfNew = false
end
end)
Are you setting the text and bar of the Gui to the values? I think It could be because your script only changes the text and bar when the value is updated, but when you clone the UI it’s still preset to what you set it to, since the fuel/bombs/health values haven’t changed yet
so to prevent I stopped it from cloning, so that it only changes the parent of the gui. But now i have new problems, every time i try to call the tween() it says that i attempted to call a boolean value
crisis and tear avoided, turns out im stupid and i set the parent of the gui to nil when the player left, so im assuming the thing deleted itself lol. no remote event or anything funky required, if you just hop in now it works. I changed it from nil to the script it is originally parented to.