Hello again.
So I have this locker system that you can hide in, it works fine, until you realize it doesn’t work in multiplayer properly.
Problem:
Well, it works in multiplayer for my test, but if a player happen to dies or leave while being in locker, my script doesn’t detect that, and it will still assume someone is using the locker, making it stuck.
This is the video of it.
(I held the button all the way at the end, although the text didn’t showed up because I made change to it)
What I want to do is to get humanoid from the server script, to detect if the player leave or died while being in the locker so the locker could unlock itself.
Though, I don’t know how to do that, I’ve tried to use findfirstchild, but that doesn’t work, or I don’t know how to use it properly.
I’ve tried to use local script and event, but afraid of it being exploited, so I removed it.
Here’s the workspace view:
script:
--Open tween
local tweenservice = game:GetService("TweenService")
local part = script.Parent.Parent.Hinge
local OriginalPos = script.Parent.Parent.Closed.Position
local TargetPos = script.Parent.Parent.Opened.Position
local OriginalOri = script.Parent.Parent.Closed.Orientation
local TargetOri = script.Parent.Parent.Opened.Orientation
local info = TweenInfo.new(
0.3,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goal =
{
Position = OriginalPos
,
Orientation = OriginalOri
}
local tween = tweenservice:Create(part,info,Goal)
--Close tween
local tweenservice2 = game:GetService("TweenService")
local part2 = script.Parent.Parent.Hinge
local OriginalPos2 = script.Parent.Parent.Opened.Position
local TargetPos2 = script.Parent.Parent.Closed.Position
local OriginalOri2 = script.Parent.Parent.Opened.Orientation
local TargetOri2 = script.Parent.Parent.Closed.Orientation
local info2 = TweenInfo.new(
0.3,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goal2 =
{
Position = OriginalPos2
,
Orientation = OriginalOri2
}
local tween2 = tweenservice2:Create(part2,info2,Goal2)
--The locker system
local Hiding = false
local Hider = nil
local HidingPos = script.Parent.Parent.HidePosition
local ExitPos = script.Parent.Parent.ExitPosition
function Hide(Clicker) --Thanks to RFL890 for helping on this part.
if Hiding == false and Clicker.Character.Humanoid.Health >= 1 then
Hiding = true
Hider = Clicker.Name
Clicker.Character.Humanoid.WalkSpeed = 0
workspace.CurrentCamera.CameraSubject = Clicker.Character.Head
Clicker.CameraMode = Enum.CameraMode.LockFirstPerson
Clicker.Character.HumanoidRootPart.Anchored = true
Clicker.Character.HumanoidRootPart.CFrame = CFrame.new(HidingPos.Position, ExitPos.Position)
local Anim2 = Instance.new("Animation")
Anim2.AnimationId = "rbxassetid://6534399775"
Anim2.Name = "Hiding"
Anim2.Parent = Clicker.Character
local Hum = Clicker.Character.Humanoid:LoadAnimation(Clicker.Character.Hiding)
Hum:Play()
elseif Hiding == true then
if Clicker.Character.HumanoidRootPart.Anchored == true then
Hider = nil
for _, k in ipairs(Clicker.Character.Humanoid:GetPlayingAnimationTracks()) do
k:Stop()
end
Clicker.Character.Humanoid.WalkSpeed = 11
workspace.CurrentCamera.CameraSubject = Clicker.Character.Humanoid
Clicker.Character.HumanoidRootPart.Anchored = false
Clicker.Character.HumanoidRootPart.CFrame = CFrame.new(ExitPos.Position, HidingPos.Position)
Clicker.CameraMode = Enum.CameraMode.Classic
Hiding = false
elseif Clicker.Character.HumanoidRootPart.Anchored == false then
Clicker.PlayerGui.Subtitle.Text.Frame.Text = "This locker is already being used!"
Clicker.PlayerGui.Subtitle.Text.Frame.TextTransparency = 0
Clicker.PlayerGui.Subtitle.Text.Frame.TextStrokeTransparency = 0
wait(3)
Clicker.PlayerGui.Subtitle.Text.Frame.Frame.Text = "..."
Clicker.PlayerGui.Subtitle.Text.Frame.TextTransparency = 1
Clicker.PlayerGui.Subtitle.Text.Frame.TextStrokeTransparency = 1
end
end
end
script.Parent.ProximityPrompt.Triggered:Connect(Hide)
function Activating(Clicker)
tween2:Play()
script.Parent.LockerOpen:Play()
Clicker.Character.Humanoid.WalkSpeed = 0
end
script.Parent.ProximityPrompt.PromptButtonHoldBegan:Connect(Activating)
function Deactivate(Clicker)
tween:Play()
script.Parent.LockerClose:Play()
Clicker.Character.Humanoid.WalkSpeed = 11
end
script.Parent.ProximityPrompt.PromptButtonHoldEnded:Connect(Deactivate)
If you could help me with this it’d be appreciated.