What is the issue? Can’t do it, tried adding functions but doesn’t work.
What solutions have you tried so far? I looked for solutions but didn’t find any.
The script:
local pp = script.Parent:WaitForChild("ProximityPrompt")
local d = false
local a = script.Parent:WaitForChild("Animation")
pp.Triggered:Connect(function(p)
local c = p.Character or p.CharacterAdded:Wait()
local v = c:WaitForChild("isHiding")
local h = c:WaitForChild("Humanoid")
local r = c:WaitForChild("HumanoidRootPart")
local t = h:LoadAnimation(a)
if not d then
d = true
v.Value = true
pp.ActionText = "Go Out"
t:Play()
r.Position = script.Parent.Parent.Positions.Pos.Position
r.Anchored = true
r.CanCollide = false
r.Orientation = script.Parent.Parent.Positions.Pos.Orientation
h.AutoRotate = false
script.Parent:WaitForChild("isOccupied").Value = true
else
v.Value = false
pp.ActionText = "Hide"
for i, v in pairs(h:GetPlayingAnimationTracks()) do
v:Stop()
end
r.Position = script.Parent.Parent.Positions.OutPos.Position
r.Anchored = false
r.CanCollide = true
h.AutoRotate = true
script.Parent:WaitForChild("isOccupied").Value = false
d = false
end
end)
Yes, the exact thing i really need here is to know if it’s occupied or not, so if someone triggers the prompt, and someone’s using the bed, it just returns end.
Try just setting an occupied boolen attribute when they player is in the bed something like this below i also commented so you can learn what each change does
local pp = script.Parent:WaitForChild("ProximityPrompt")
--local d = false -- if this is the occupied debounce don't think you need it here
local Debounce -- use this as local debounce to give alittle time between clicks
local a = script.Parent:WaitForChild("Animation")
pp.Triggered:Connect(function(p)
if Debounce then return end -- already clicked
Debounce = true
-- using delay function like this guarantees debouce reset even with error
delay(1, function() -- delay 1 second then remove debounce so it can be clicked again
Debounce = nil
end)
local c = p.Character or p.CharacterAdded:Wait()
local v = c:WaitForChild("isHiding")
local h = c:WaitForChild("Humanoid")
local r = c:WaitForChild("HumanoidRootPart")
local t = h:LoadAnimation(a)
if not script.Parent:GetAttribute('Occupied') then -- checks if its not occupied.. if not set to occupied else set unoccupied
script.Parent:SetAttribute('Occupied', true) -- sets the attribute as boolen to true
v.Value = true
pp.ActionText = "Go Out"
t:Play()
r.Position = script.Parent.Parent.Positions.Pos.Position
r.Anchored = true
r.CanCollide = false
r.Orientation = script.Parent.Parent.Positions.Pos.Orientation
h.AutoRotate = false
--script.Parent:WaitForChild("isOccupied").Value = true -- don't think you need this just use attributes
else
v.Value = false
pp.ActionText = "Hide"
for i, v in pairs(h:GetPlayingAnimationTracks()) do
v:Stop()
end
r.Position = script.Parent.Parent.Positions.OutPos.Position
r.Anchored = false
r.CanCollide = true
h.AutoRotate = true
script.Parent:SetAttribute('Occupied', nil) -- removes the attribute so it shows not occupied anymore
--script.Parent:WaitForChild("isOccupied").Value = false -- don't think you need this just use attributes
end
end)