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

Team Door Script Fix help needed for Roblox Studio Project ?

Asked by 1 year ago
Edited 1 year ago

Can anyone help me this script ? Half script is right but access to team is incorrect :

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local TweenService = game:GetService("TweenService")
local door = script.Parent.Door
local trigger = script.Parent.Trigger
local SoundOpen = script.Parent.SoundOpen
local SoundClose = script.Parent.SoundClose

local goalClose = {CFrame = CFrame.new(-32.389, 3.595, -2.126) * CFrame.Angles(0, math.rad(180), 0)}
local goalOpen = {CFrame = CFrame.new(-34.693, 3.595, -0.063) * CFrame.Angles(0, math.rad(90), 0)}

local tweenInfo = TweenInfo.new(1)

local tweenOpen = TweenService:Create(door, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(door, tweenInfo, goalClose)

local function isValidPlayer(player)
    return player and player.Parent and player.Team == Teams["Police"]
end

local function openDoor(player)
    if isValidPlayer(player) then
        SoundOpen:Play()
        tweenOpen:Play()
        wait(2)
        tweenClose:Play()
        SoundClose:Play()
    end
end

trigger.Touched:Connect(function(hit)
    local character = hit.Parent
    local player = Players:GetPlayerFromCharacter(character)
    openDoor(player)
end)

0
What is the reason for returning player and player.Parent? xInfinityBear 1777 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

You can check if the player's TeamColor is the same as the TeamColor of the Police Team.

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local policeTeam = Teams:WaitForChild("Police")

local TweenService = game:GetService("TweenService")
local door = script.Parent.Door
local trigger = script.Parent.Trigger
local SoundOpen = script.Parent.SoundOpen
local SoundClose = script.Parent.SoundClose

local goalClose = {["CFrame"] = (CFrame.new(-32.389, 3.595, -2.126) * CFrame.Angles(0, math.rad(180), 0))}
local goalOpen = {["CFrame"] = (CFrame.new(-34.693, 3.595, -0.063) * CFrame.Angles(0, math.rad(90), 0))}

local tweenInfo = TweenInfo.new(1)

local tweenOpen = TweenService:Create(door, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(door, tweenInfo, goalClose)

local function isValidPlayer(player)
    return (player and player.Parent and player.TeamColor == policeTeam.TeamColor and player.Team.Name == policeTeam.Name)
end

local function openDoor(player)
    if isValidPlayer(player) then
        SoundOpen:Play()
        tweenOpen:Play()
        task.wait(2)
        tweenClose:Play()
        SoundClose:Play()
    end
end

trigger.Touched:Connect(function(hit)
    local character = hit.Parent
    local player = Players:GetPlayerFromCharacter(character)
    openDoor(player)
end)
0
Thank you. juliusznajer -2 — 1y
Ad

Answer this question