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

Making an action only occur when another one has?

Asked by 4 years ago

Heya, it's me and my dumb buttons again.

So since last time I managed to make client sided buttons that activated on every child that can be activated by an event.

I have two buttons - one that fires a good quality (making the platform visible) and one that fires a bad quality (making the platform non-collidable)

My script for each in SeverScriptStorage is as shown

local ButtonPlatform = workspace.Button.ButtonPlatforms
local ButtonPressed = false

game.ReplicatedStorage.PropertyChangeGood.OnClientEvent:Connect(function()
    if not ButtonPressed then

        ButtonPressed = true

    for i, v in pairs (ButtonPlatform:GetChildren()) do

    v.Transparency = 0
    v.CanCollide = true
     game.Players.LocalPlayer.PlayerScripts.SuccessSound:Play()

ButtonPressed = false

    end end end)

and

local ButtonPlatform = workspace.Button.ButtonPlatforms
local ButtonPressed = false

game.ReplicatedStorage.PropertyChangeBad.OnClientEvent:Connect(function()
    if not ButtonPressed then

        ButtonPressed = true

    for i, v in pairs (ButtonPlatform:GetChildren()) do

    v.Transparency = 0.5
    v.CanCollide = false

ButtonPressed = false

    end end end)

this script works perfectly as intended, however if one stays standing on the block that fires the PropertyChangeGood, the sound plays over and over again and lags out the player (whilst also creating a abnormally loud environment.)

I was wondering if there was a way to only be able to active PropertyChangeGood if PropertyChangeBad has been fired before it? So if PropetyChangeGood were to be activated it would only work if PropertyChangeBad was true at the current time.

(Also ignore the irrelevant debouncer in the script, it doesn't do anything bad or good and I'm too lazy to get rid of it)

Thanks again hehe

1 answer

Log in to vote
0
Answered by 4 years ago

What I would do is put a BoolValue in ReplicatedStorage and name it "PropertyChangedGood". We can check this value before running one of the events. To include this in your scripts, you would change them to look like this:

local ButtonPlatform = workspace.Button.ButtonPlatforms
local ButtonPressed = false

game.ReplicatedStorage.PropertyChangeGood.OnClientEvent:Connect(function()
 local replicatedStorage = game:GetService("ReplicatedStorage")
local propertyChangedGood = replicatedStorage.PropertyChangedGood
 if not ButtonPressed and propertyChangedGood == false then

        ButtonPressed = true

    for i, v in pairs (ButtonPlatform:GetChildren()) do

    v.Transparency = 0
    v.CanCollide = true
     game.Players.LocalPlayer.PlayerScripts.SuccessSound:Play()

ButtonPressed = false

    end end end)

and

local ButtonPlatform = workspace.Button.ButtonPlatforms
local ButtonPressed = false

    game.ReplicatedStorage.PropertyChangeBad.OnClientEvent:Connect(function()
    local replicatedStorage = game:GetService("ReplicatedStorage")
    local propertyChangedGood = replicatedStorage.PropertyChangedGood
    if not ButtonPressed and propertyChangedGood.Value == true then'
    propertyChangedGood.Value = false
        ButtonPressed = true

    for i, v in pairs (ButtonPlatform:GetChildren()) do
     v.Transparency = 0.5
        v.CanCollide = false

    ButtonPressed = false

    end end end)

I think this should work but I can't be sure without seeing your studio setup. Hope I helped out!

0
damn dude you are so helpful, youve literally commented on every single one of my posts now. you really are the best. ill check this out when i get home from school today. you rock!! ittyisaduck 21 — 4y
Ad

Answer this question