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

How do I make a pressure plate deactivate an event when you stop touching it?

Asked by 4 years ago
Edited 4 years ago

I have a slight problem where when I touch the pressure plate, it won't stop the event it's supposed to hold. There is a BindableFunction named Plate1Function and there are 2 scripts, FunctionHolder, and Event. The Event script is parented under a part named Plate and the Plate is parented under a Model named Plate1. There is a BoolValue also parented under Plate which is named _IsActivated. I am grouping all of this once I have completed the project, as I am making a map for a game.

Here's the script for the Event.

script.Parent.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        script.Parent._IsActivated.Value = true
        if script.Parent._IsActivated.Value == true then
            local Plate1 = script.Parent.Parent.Parent.Plate1Function
        elseif game.Players:GetPlayerFromCharacter(hit.Parent) == false then
            script.Parent._IsActivated = false
        end
    end
return end)

I want FunctionHolder to hold all functions for each pressure plate. I am starting for Plate1. Whenever my character was on the pressure plate, the event would happen. When my character is off the pressure plate, the event for turning the object to transparency 0.6 and CanCollide off will still run. I would need help with what text to put inside the FunctionHolder script.

Here's the script for FunctionHolder. I haven't put anything inside it since I do not understand what to put. The code I want to put in is whether the BoolValue inside Plate is active or not, then the function will happen.

script.Parent.Plate1Function.OnInvoke = function()
    --code?????
end

Does anyone know how to fix this situation?

1 answer

Log in to vote
0
Answered by 4 years ago

you could use connections if I'm not mistaken.

local connection
connection = script.Parent.Plate1Function.OnInvoke:Connect(function()
connect:disconnect()
end)

https://developer.roblox.com/en-us/recipes/How-to-disconnect-an-event-connection

Ad

Answer this question