Hello all and hope everyone is doing great. I’m fairly new to scripting, still consider myself a script kitty and want to make a horror game with some of my acquired knowledge. Had a few issues and eventually got past them but this one script for my bush seems to have me stumped. Been waiting to be able to post on here and maybe get some helpful feedback and possibly an answer to my problem. Thank you all for taking the time to read my post and looking into my problem.
You can write your topic however you want, but you need to answer these questions:
-
I’m trying to make a bush for any player to hide in within this horror experience.
-
The issue is the player cannot hide back in the same bush. So the way the bush works it when close to the bush, the player can use the proximity prompt to enter the bush and once they start moving forward or any direction a few studs they come out of hiding. Problem is mainly the proximity prompt does not re-enable allowing the user to hide back in the bush they just left.
-
I’ve tried looking for solutions on scriptures help and using the robot (Chatgpt) to help find a solution but unfortunately neither could give a good answer. Even decided to go a different route for how I would make the bush work but really don’t wanna give up on my script.
Here is the code for the hiding bush, also the script is in a folder in the workspace which contains the bush models I am using:
…
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("HideEvent")
local bush = script.Parent:GetChildren()
-- Function to check if the player moved and set "Hiding" to false if they did
local function checkPlayerMovement(player)
local character = player.Character
if not character then return end
local initialPosition = character.PrimaryPart.Position
while player and player.Parent do
task.wait(1) -- Adjust the frequency of checking as needed
local currentPosition = character.PrimaryPart.Position
local distance = (currentPosition - initialPosition).Magnitude
if distance > 1 then -- Adjust the threshold as needed
player.Hiding.Value = false
break
end
end
end
for i, v in pairs(bush) do
if v:IsA("Model") then
local playerHiding = nil
local prompt = v.PromptPart.Prompt
prompt.Triggered:Connect(function(player)
local character = player.Character
if not character then return end
if not playerHiding then
prompt.Enabled = false
playerHiding = player
player.Hiding.Value = true
character:PivotTo(v.InsidePos.CFrame)
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpHeight = 0
event:FireClient(player, v)
task.wait(0.5)
event.OnServerEvent:Connect(function(player, model)
if model == bush then
local character = player.Character
if character and character.Humanoid.Health > 0 then
character:PivotTo(v.OutsidePos.CFrame)
character.Humanoid.Walkspeed = 12
character.Humanoid.JumpHeight = 7.2
prompt.Enabled = true
playerHiding = nil
player.Hiding.Value = false
end
end
end)
-- Start checking player movement
spawn(function()
checkPlayerMovement(playerHiding)
end)
end
end)
end
end
game.Players.PlayerAdded:Connect(function(player)
local hiding = Instance.new("BoolValue", player)
hiding.Name = "Hiding"
hiding.Value = false
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
if player.Hiding and player.Hiding.Value == true then
player.Hiding.Value = false
end
end)
end)
end)
…