Hi, I’ve been trying to debug this code for the past 5-6 hours and still can’t figure out what needs to be fixed. What I am trying to do is make it so that if the player opens the door using a key, that player will become the new piggy and the current piggy will become a contestant. What the issue is is that the code seen below isn’t reached whatsoever. What ami I doing wrong? The full code is below the code.
for i, player in pairs(game.Players:GetPlayers()) do
local Player = game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Key"))
if Player then
local NTBP = Player:FindFirstChild("NeedToBePiggy")
if NTBP then
local map = game.Workspace:FindFirstChild("Map")
local mapSpawns = map.PlayerSpawns:GetChildren()
Player.NeedToBePiggy:Destroy()
print("NeedToBePiggyTag Destroyed")
RoundModule.InsertNewTag(Player, "Piggy")
print(" has new Piggy Tag")
wait(.1)
RoundModule.DressNewPiggy(Player)
print("Player is now dressed as piggy")
wait(.1)
RoundModule.TeleportPiggy(Player, mapSpawns)
print("Player is teleported to map")
end
end
end
Door Module Script
local module = {}
local tweenService = game:GetService("TweenService")
local RoundModule = require(script.Parent.RoundModule)
-- swing the door by `angle` degrees
function module.swingDoor(angle,door)
-- locate the hinge on the door
local hingeBefore = door.CFrame * CFrame.new(-2.5, 0, 0)
-- relative to the hinge, where is the door?
local relative = hingeBefore:toObjectSpace(door.CFrame)
-- twist the hinge
-- CONVERT angle *from* degrees *to* radians here
local hingeAfter = hingeBefore * CFrame.Angles(0, math.rad(angle), 0)
-- re-attach the door to the new "hinge"
local tweenProperties = TweenInfo.new(0.2) -- Time
local result = {CFrame = hingeAfter:toWorldSpace(relative)}
door.CanCollide = false
local tween = tweenService:Create(door,tweenProperties,result)
tween:Play()
wait(0.2)
door.CanCollide = true
end
function module.ActivateDoors(doorFolder)
for _, door in pairs(doorFolder:GetChildren()) do
if door:FindFirstChild("Key") then
door.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Key") then
if door.Key.Value == hit.Parent.Name then
if door.Name == "ExitDoor" then
if door.Generator.On.Value == true and not door:FindFirstChild("WoodBlock") then
door.Padlock.Anchored = false
wait(1)
door.Transparency = 1
door.CanCollide = false
door.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChild("Contestant") and not player:FindFirstChild("Escaped") then
local Escaped = Instance.new("BoolValue")
Escaped.Name = "Escaped"
Escaped.Parent = player
game.ReplicatedStorage.Announcement:FireClient(player,"You Escaped")
end
end
end)
end
else
door.Padlock.Anchored = false
wait(0.5)
door:Destroy()
if hit.Parent:FindFirstChild("Key") then
local char = hit.Parent:FindFirstChild("Key")
local playerWhoTouched = game:GetService("Players"):GetPlayerFromCharacter(char)
print("Your name is : ")
RoundModule.InsertNewTag(playerWhoTouched, "NeedToBePiggy")
print("New tag added")
end
for i, player in pairs(game.Players:GetPlayers()) do
local Player = game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Key"))
if Player then
local NTBP = Player:FindFirstChild("NeedToBePiggy")
if NTBP then
local map = game.Workspace:FindFirstChild("Map")
local mapSpawns = map.PlayerSpawns:GetChildren()
Player.NeedToBePiggy:Destroy()
print("NeedToBePiggyTag Destroyed")
RoundModule.InsertNewTag(Player, "Piggy")
print(" has new Piggy Tag")
wait(.1)
RoundModule.DressNewPiggy(Player)
print("Player is now dressed as piggy")
wait(.1)
RoundModule.TeleportPiggy(Player, mapSpawns)
print("Player is teleported to map")
end
end
end
for i, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("Piggy") then
local map = game.Workspace:FindFirstChild("Map")
local mapSpawns = map.PlayerSpawns:GetChildren()
wait(2)
v.Piggy:Destroy()
v:LoadCharacter()
wait(1)
RoundModule.InsertNewTag(v, "Contestant")
wait(.1)
RoundModule.TeleportNewPlayer(v, mapSpawns)
print("Piggy: ".. v.Name.. "is now a contestant")
end
end
end
end
end
end)
else
if not door:FindFirstChild("ClickDetector") then local cd = Instance.new("ClickDetector") cd.Parent = door end
local debounce = false
door:FindFirstChild("ClickDetector").MouseClick:Connect(function(player)
if door.Name == "Door" then
if not debounce then
debounce = true
local angle
if door:FindFirstChild("Open") then
angle = -90
door.Open:Destroy()
else
angle = 90
local openVal = Instance.new("StringValue")
openVal.Name = "Open"
openVal.Parent = door
end
module.swingDoor(angle,door)
wait(.001)
print("Door swung!")
wait(1)
debounce = false
end
end
end)
end
end
end
return module
NOTE: This will not be a piggy game, the script that I have provided is an added on version, meaning I created parts from it that weren’t part of the tutorial. I really need help on this as it’s a main feature coming to the game. Any help will be appreciated!