I have this garage door right here, pretty simple with a tween playing when someone activates it.
It’s part of a Suburban Home I built, and I want to rent that out. Hence I want only the owner of the House to be able to open the door. I just don’t know how.
Script:
local TS = game:GetService("TweenService")
local Part = script.Parent
local prox = Part.ProximityPrompt
local proxTriggered = 0
local function OpenTween()
local info = TweenInfo.new(
0.2,
Enum.EasingStyle.Sine,
Enum.EasingDirection.In,
0,
false,
0
)
local goals =
{
Transparency = 1,
CanCollide = false
}
local tween = TS:Create(Part, info, goals)
tween:Play()
end
local function CloseTween()
local info = TweenInfo.new(
0.2,
Enum.EasingStyle.Sine,
Enum.EasingDirection.In,
0,
false,
0
)
local goals =
{
Transparency = 0,
CanCollide = true
}
local tween = TS:Create(Part, info, goals)
tween:Play()
end
prox.Style = Enum.ProximityPromptStyle.Default
prox.HoldDuration = 0.2
prox.ActionText = "Open"
prox.ObjectText = "Door"
prox.Triggered:Connect(function()
proxTriggered = proxTriggered + 1
if proxTriggered == 1 then
prox.ActionText = "Close"
OpenTween()
elseif proxTriggered > 1 then
prox.ActionText = "Open"
proxTriggered = 0
CloseTween()
end
end)
Though I am doofus at scripting, maybe I have to check the UserID and then proceed with the script and tween playing itself?
Thanks for any tip…
PS: As I said, I’m still learning scripting, so please, try to make the tips noob friendly
I would create the Proximity Prompt under a LocalScript so that the only person with the Proximity Prompt is the Owner. Create the ProximityPrompt when the Player Buys the home.
You could check if the player who is using the prompt is the Owner of the house. Like this:
prox.Triggered:Connect(function(player) -- Player is the Player that used the Proximity Prompt
if player.Name == OwnerOfHouse then
-- open the door
end
end)
The name of the Owner, but if you wanted it to be UserID, you would do:
prox.Triggered:Connect(function(player) -- Player is the Player that used the Proximity Prompt
if player.UserId == OwnerOfHouse then
-- open the door
end
end)
local TS = game:GetService("TweenService")
local Part = script.Parent
local prox = Part.ProximityPrompt
local ProxTriggered = 0
prox.Triggered:Connect(function(player)
-- your script
end)
The way you currently have it, you are trying to call the variable “prox” before you have defined it. It is like doing this:
print(x)
local x = 'hi'
This doesn’t work, because you print the variable before you define it.