Hello guys,
I have an issue with my script which is changes the Frame's Background Transparency in StarterGUI that slowly decreases it's transparency when there's low oxygen in my game and it increases again to 1 after there's an enough oxygen again. The problem is; it works pretty well in the beginning but it never works again when the oxygen decreases again.
Here's the script:
while wait() do if game.Workspace.OxGenPlrDying.Value==true then script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if game.Workspace.OxGenRestartComplete.Value==true then game.Workspace.OxGenPlrDying.Value=false game.Workspace.OxGenPlrHealing.Value=true end elseif game.Workspace.OxGenPlrHealing.Value==true then script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency==1 then game.Workspace.OxGenPlrHealing.Value=false end end end
A small note: The script's location that i'm talking about is game.StarterGui.DrownGUI.Frame.Script
You mentioned that it was a regular script in a Frame...
Before I share my answer I'll share with you an experience i had with doing the same thing:
When I click on a part, a gui (The frame) is supposed to pop up... however it pops up only ONCE. After I closed it, it never pops up again. I think the logic is the same behind this.
Therefore, I used RemoteEvents
and put the script in a local script instead, and it worked perfectly fine after that.
I have a way out here that (possibly) works
[[EDIT]]after the comments:
you mentioned that the real problem is really only about the Gui and the transparency not working.
that is because your old script was a Server-sided script inside a Frame. This cannot be used to change the transparency of the frame, as changing the transparency of a Frame would require a LocalScript. That's why we use the RemoteEvents to detect whether the oxygen breaking etc. changed
this is the server sided script in the workspace
local OxGenPlrDying = workspace.OxGenPlrDying local OxGenIsOnAction = workspace.OxGenIsOnAction local OxGenPlrHealing = workspace.OxGenPlrHealing --etc etc you get the idea local RE = game:GetService("ReplicatedStorage").RemoteEvent OxGenPlrDying:GetPropertyChangedSignal("Value"):Connect(function() RE:FireAllClients(OxGenPlrDying.Value,OxGenIsOnAction.Value,OxGenPlrHealing.Value)--add more parameters if you need!!! OxGenIsOnAction:GetPropertyChangedSignal("Value"):Connect(function() RE:FireAllClients(OxGenPlrDying.Value,OxGenIsOnAction.Value,OxGenPlrHealing.Value)--add more parameters if you need!!! OxGenPlrHealing:GetPropertyChangedSignal("Value"):Connect(function() RE:FireAllClients(OxGenPlrDying.Value,OxGenIsOnAction.Value,OxGenPlrHealing.Value)--add more parameters if you need!!! --I think whenever each of the property changes you need to fire the local script to change the transparency end)
The local script in the frame:
local function changeBackgroundTransparency(your_parameters) repeat wait(0.001) if game.Workspace.OxGenPlrDying.Value==true then -- remove every game.Workspace if you renamed your paremeter to OxGenPlrDying script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if game.Workspace.OxGenRestartComplete.Value==true then game.Workspace.OxGenPlrDying.Value=false game.Workspace.OxGenPlrHealing.Value=true end elseif game.Workspace.OxGenPlrHealing.Value==true then script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency==1 then game.Workspace.OxGenPlrHealing.Value=false end end until script.Parent.BackgroundTransparency = 1 --i'm assuming you want it to be completely invisible. end RE.OnClientEvent:Connect(function(your_parameters) changeBackgroundTransparency(your_parameters) end)
So the logic here is that when oxygen level change, you fire the remote event which triggers the background transparency. it'll keep repeating the decrease/increase of background transparency until it gets the desired level.
i hope this was what you meant by your main problem
[ EDIT 2 ]
This is the first script, local script in the frame
local RE = game:GetService("ReplicatedStorage").RemoteEvent local function changeBackgroundTransparency(OxGenPlrDying,OxGenRestartComplete) while wait(0.001) do if OxGenPlrDying==true then print("Player Dying") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if OxGenRestartComplete==true then OxGenPlrDying.Value=false end elseif OxGenPlrDying==false then print("Player Healing") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency==1 then end end end RE.OnClientEvent:Connect(function(OxGenPlrDying,OxGenRestartComplete) --i changed the line below AND above, I removed the .Value from each. As well as everything above, I removed the .Value . I ' m actually not very sure whether it'll affect the script or not but from what I remember it'll cause an error if you have a `.` in your parameter changeBackgroundTransparency(OxGenPlrDying,OxGenRestartComplete) end) end
Your second script should be fine.
For the third script, any particular reason to disable it? How are you going to enable it after disabling it?
[EDIT 3] The second script, I edited it a bit.
local OxGenPlrDying = workspace.OxGenPlrDying local OxGenIsOnAction = workspace.OxGenIsOnAction local OxGenRestartComplete = workspace.OxGenRestartComplete local RE = game:GetService("ReplicatedStorage").RemoteEvent OxGenPlrDying:GetPropertyChangedSignal("Value"):Connect(function() RE:FireAllClients(OxGenPlrDying.Value,OxGenRestartComplete.Value) end) OxGenRestartComplete:GetPropertyChangedSignal("Value"):Connect(function() RE:FireAllClients(OxGenPlrDying.Value,OxGenRestartComplete.Value) end) --and if you need; OxGenIsOnAction:GetPropertyChangedSignal("Value"):Connect(function() RE:FireAllClients(OxGenPlrDying.Value,OxGenRestartComplete.Value) --you may have to add a OxGenIsOnAction parameter end)
[EDIT 4] I edited your first script a little more. I reckon the problem should be in here since it didn't print out what's necessary.
local RE = game:GetService("ReplicatedStorage").RemoteEvent RE.OnClientEvent:Connect(function(OxGenPlrDying,OxGenRestartComplete) while wait(0.001) do if OxGenPlrDying==true then print("Player Dying") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if OxGenRestartComplete==true then OxGenPlrDying.Value=false end elseif OxGenPlrDying==false then print("Player Healing") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency==0 or script.Parent.BackgroundTransparency==1 then break end end end end) --I may have missed out an "end" somewhere but most likely not
[EDIT 5]
I further edited your first script. Hopefully this works a bit better. Also sorry for the really late reply, was quite busy
local RE = game:GetService("ReplicatedStorage").RemoteEvent RE.OnClientEvent:Connect(function(OxGenPlrDying,OxGenRestartComplete) while wait(0.001) do if OxGenPlrDying==true then print("Player Dying") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if OxGenRestartComplete==true then OxGenPlrDying.Value=false end elseif OxGenPlrDying==false then print("Player Healing") end script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency==0 or script.Parent.BackgroundTransparency==1 then break end end end)
[EDIT 6] Well this seems pretty challenging to me. None of the above solutions really worked... no really sure if this will now. To be honest i don't know why Player Dying and Player Healing keep printing... the only reason for that is that the BoolValue keeps alternating between false and true. At this point, really the only way is to keep trying different methods of writing your script add a remotefunction called "RemoteFunction" to your replicated storage and try this!
your first script (local script): warning this may cause lag but hopefully it doesn't
local RE = game:GetService("ReplicatedStorage").RemoteEvent local RF = game:GetService("ReplicatedStorage").RemoteFunction RE.OnClientEvent:Connect(function(OxGenPlrDying) while wait(0.001) do if OxGenPlrDying==true then print("Player Dying") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if workspace.OxGenRestartComplete.Value == true then RF:InvokeServer() end elseif OxGenPlrDying==false then print("Player Healing") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 end if script.Parent.BackgroundTransparency==0 or script.Parent.BackgroundTransparency==1 then break end end end)
in another new script [Script 4] a Server-Sided-Script in Server-Script-Service:::::::
local RF = game:GetService("ReplicatedStorage").RemoteFunction RF.OnServerInvoke = function() workspace.OxGenPlrDying.Value = false end
i'm actually quite confident that this will work now lol, if it still doesn't that would be quite sad xD.
i deleted the first draft because when i tried to edit it said : "Whoa there! That's some awful long text. Please stay below 10,000 characters!
"
If you don't already have the answer it's because when oxygen restarts, the oxygen restart value is true so when you try it again it's still true and stops everything so use this. (I think this will work)
while wait() do if game.Workspace.OxGenPlrDying.Value==true then script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if game.Workspace.OxGenRestartComplete.Value==true then -- This value doesn't become false again game.Workspace.OxGenRestartComplete.Value = false -- This is what you need to do to make it stop restarting game.Workspace.OxGenPlrDying.Value=false game.Workspace.OxGenPlrHealing.Value=true end elseif game.Workspace.OxGenPlrHealing.Value==true then script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency==1 then game.Workspace.OxGenPlrHealing.Value=false end end end
Hope I could help!
I knew that the problem wasn't supposed to be that huge and confusing...
I fixed the problem myself by a couple small changes in my old script. I was pretty tired and I couldn't figure out what's the problem in the day that I asked this question.
But you may be asking right now, how did I fix it? I already knew that I'm not supposed to have another variable or something more confusing in my script. So, I decided to look at to my old script again and made some small changes.
As I told people in my question, the problem was about the script were only working for once. I tried to find what's the problem again just a few minutes ago, and I fixed it in a few minutes.
I'm so tired today and I really can't tell what did I change to fix the script rn. I'll just copy+paste my script right here, so you can check it out.
while wait(0.001) do if game.Workspace.PlrDyingIngition.Value==true then if game.Workspace.OxGenPlrDying.Value==true then print("Player Dying") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency-0.0001 if game.Workspace.OxGenRestartComplete.Value==true then game.Workspace.OxGenPlrDying.Value=false end elseif game.Workspace.OxGenPlrDying.Value==false then print("Player Healing") script.Parent.BackgroundTransparency=script.Parent.BackgroundTransparency+0.01 if script.Parent.BackgroundTransparency>0.99 then game.Workspace.PlrDyingIngition.Value=false end end end end
I'm really sorry for people who's trying to help me since 4 days. It was completely my fault and my stupidity. But I'm pretty happy and relaxed when I fixed that trouble which was bothering us all. Have a good day all!