Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

code isn't working to make the gravity and lighting and map colour back to normal?

Asked by 4 years ago

Hello everyone, I am making a game where when you press a button something happens, there is a problem though, I have made my game so the has a 50 50 chance of going low gravity and when it does go low gravity it will make the map grey and make some parts/models visible, although most of the code worked some didn't, as you can see on line 36 I made it so it goes back to normal (the time of day and the parts disappear again and gravity goes back to normal after 12 seconds), all of the code making it turn into low gravity and using the if statement to make the parts visible worked but the if statment on line 36 making it back to normal didn't . The scripit is a normal script not a local or module, its parent is the button you press to do the 5050 chance. Hopefully this isn't just roblox and you scripters can help me out, thank you!

The script is below, line 36 is the if statement that was supposed to make it back to normal.

01local lighting = game.Lighting
02local button = script.Parent
03local ClickDetector = Instance.new("ClickDetector")
04ClickDetector.Parent = button
05ClickDetector.MaxActivationDistance = 15
06 
07ClickDetector.MouseClick:Connect(function()
08    print("Button has been clicked.")
09    button.Transparency = 1
10    game.Workspace.Stand.Transparency = 1
11    game.Workspace.Stand.CanCollide = false
12    button.CanCollide = false
13    wait(0.4)
14    local variable = math.random(1, 2)
15    if variable == 1 then
View all 61 lines...

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I am sure why you are using if workspace.Gravity == 30 then do, instead you should not add do there. Also, you are checking your Gravity value twice in the same code which is pretty much useless. Well, you can try doing :

01if game.Workspace.Gravity == 30 then
02            game.Workspace.World.BrickColor = BrickColor.new("Mid gray")
03            game.Workspace.SA.Transparency = 0
04            game.Workspace.SA.CanCollide = true
05            game.Workspace.SpaceRock.Transparency = 0
06            game.Workspace.SpaceRock.CanCollide = true
07            game.Workspace.Z.Transparency = 0
08            game.Workspace.Z.CanCollide = true
09            game.Workspace.SRock.Transparency = 0
10            game.Workspace.SRock.CanCollide = true
11            game.Workspace.L.Transparency = 0
12            game.Workspace.L.CanCollide = true
13            game.Workspace.Y.Transparency = 0
14            game.Workspace.Y.CanCollide = true
15            lighting.TimeOfDay = 1
View all 29 lines...

Now, I am going to simplify your code, so it doesn't look messy. For this, we will be creating two custom functions for Gravity and Fog.

01function Gravity()
02            game.Workspace.World.BrickColor = BrickColor.new("Mid gray")
03            game.Workspace.SA.Transparency = 0
04            game.Workspace.SA.CanCollide = true
05            game.Workspace.SpaceRock.Transparency = 0
06            game.Workspace.SpaceRock.CanCollide = true
07            game.Workspace.Z.Transparency = 0
08            game.Workspace.Z.CanCollide = true
09            game.Workspace.SRock.Transparency = 0
10            game.Workspace.SRock.CanCollide = true
11            game.Workspace.L.Transparency = 0
12            game.Workspace.L.CanCollide = true
13            game.Workspace.Y.Transparency = 0
14            game.Workspace.Y.CanCollide = true
15            lighting.TimeOfDay = 1
View all 50 lines...

This is how your code might look:

01--//Variables
02local lighting = game.Lighting
03local button = script.Parent
04local ClickDetector = Instance.new("ClickDetector")
05ClickDetector.Parent = button
06ClickDetector.MaxActivationDistance = 15
07 
08--// Functions
09function Gravity()
10        workspace.Gravity = 30
11            game.Workspace.World.BrickColor = BrickColor.new("Mid gray")
12            game.Workspace.SA.Transparency = 0
13            game.Workspace.SA.CanCollide = true
14            game.Workspace.SpaceRock.Transparency = 0
15            game.Workspace.SpaceRock.CanCollide = true
View all 67 lines...

Lemme know if it helps!

0
Thank you! You neated up my code and made everything better. I have added some of my own code to it and your way of presenting it and I was able to ressolve the issue. TgaTheGoldenArmour 15 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

So LUA can interpret the code as if Gravity is a member of Workspace and not a propriety.

Just say if the variable = 1, then you put all the fog code into it. And if the avriable is 2, you put all the Gravity code into it:

01local lighting = game.Lighting
02local button = script.Parent
03local ClickDetector = Instance.new("ClickDetector")
04ClickDetector.Parent = button
05ClickDetector.MaxActivationDistance = 15
06 
07ClickDetector.MouseClick:Connect(function()
08    print("Button has been clicked.")
09    button.Transparency = 1
10    game.Workspace.Stand.Transparency = 1
11    game.Workspace.Stand.CanCollide = false
12    button.CanCollide = false
13    wait(0.4)
14    local variable = math.random(1, 2)
15    if variable == 1 then
View all 53 lines...

It's probably a LUA glitch treating proprieties as instances, I've had this error before.

Answer this question