Sup, I’m making a horror game with my friend where the player’s main objective is to avoid a monster, open a blast door and escape the building.
When the player open the door and exits the ending should be played and after said ending the player is sent to the main menu.
For the ending to play the player must touch an invisible exit part.
But a problem has occurred that the player can touch the part only once (The player needs to touch the part multiple times cuz the player may get the same map after a few games).
I worked on fixing the problem for hours and reading multiple posts about the same problem, but none of the solutions shown in the posts helped, nor did my attempts on fixing this.
This is the server-sided script inside the part (The server sided version’s main task is to move the player to an another folder so the game knows when to reset the map):
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.StarterGui.BatteryHUD.Spotted.Visible = false
if player then
if not player.PlayerGui.BatteryHUD.Light.Visible then
player.PlayerGui.BatteryHUD.Light.Visible = true
local tween = TweenService:Create(Light, tweenInfo, Goal)
local humanoid = player.Character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = 0
player.Character.Parent = game.Workspace.PlayerFolder.Lobby.Choosing
player.Character.HumanoidRootPart.CFrame = CFrame.new(-595.598, -94.815, 245.13)
tween:Play()
Ringing:Play()
wait(3)
Ambience:Stop()
Ringing:Stop()
--Ending plays, didn't include cuz it would be too much to throw at you
wait(2)
KeySound:Play()
MenuStatic:Play()
MenuMusic:Play()
end
end
end
end)
And the client-sided version of the script (Sends the player to the main menu):
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.StarterGui.BatteryHUD.Spotted.Visible = false
if player then
if not player.PlayerGui.BatteryHUD.Light.Visible then
player.PlayerGui.BatteryHUD.Light.Visible = true
local tween = TweenService:Create(Light, tweenInfo, Goal)
local humanoid = player.Character:FindFirstChild("Humanoid")
player.Character:WaitForChild("Humanoid").WalkSpeed = 0
player.Character.Parent = game.Workspace.PlayerFolder.Lobby.Choosing
player.Character.HumanoidRootPart.CFrame = CFrame.new(-595.598, -94.815, 245.13)
tween:Play()
Ringing:Play()
wait(3)
player.Character:WaitForChild("Humanoid").WalkSpeed = 0
print("Client")
Ambience:Stop()
Ringing:Stop()
game.Workspace.Dave.Dave.Body.Growl:Stop()
game.Workspace.Dave.Dave.Body["Spider Footsteps 3 (SFX)"]:Stop()
--Ending plays--
KeySound:Play()
wait(2)
Key:Play()
MenuStatic:Play()
MenuMusic:Play()
local MenuCam = game.Workspace.CameraPart
CurrentCam.CameraType = Enum.CameraType.Scriptable
CurrentCam.CFrame = MenuCam.CFrame
end
end
end
end)
If any more details are needed then let me know.
Any explanation behind the problem is appreciated.