i have 4 dolls scattered around the map. the player needs to collect all 4 dolls in order to unlock a room with a safe. the dolls also have numbers on them which correlate to the safe code. i have the safe script and the doll collect script working perfectly, however, i still dont know how to make the door locked until all 4 dolls are collected. each doll has a specific local script in starterGUI. i wanted to randomize it but idk how to connect the randomized code with the code for the safe. how would i make it so that the player HAS to collect all four dolls for the script that opens the door to be enabled?
maybe make a leaderstats script where everytime you get a doll a +1 is added to the leaderstats. Then in order to enter the room it checks if leaderstats = to 4.
good idea, how would would i actually put this into a script?
Simple, in serverscriptservice make an int value and leaderstat for the count. then when a player clicks a doll 1 is added.
Ex, souls would be dolls in your case.
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local souls = Instance.new("IntValue")
souls.Name = "Souls"
souls.Parent = leaderstats
local playerUserId = player.UserId
local data = playerData:GetAsync("Player_"..playerUserId)
if data then
souls.Value = data['Souls']
else
souls.Value = 0
end
end
The to add you could do…
local playersService = game:GetService('Players')
local player = playersService:FindFirstChildOfClass('Player')
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local souls = leaderstats:FindFirstChild('Souls')
if souls then
souls.Value = souls.Value + 1
end
end
end
Hopefully that works… You wil have to edit the add count script a bit to fit with getting dolls and stuff.
so do i put these into two different scripts?
Im assuming that a single player has to get all the dolls rather than a group work as a team to get the dolls?
if so then this has to all be local, so leaderstats (or even better just a IntValue in the player somewhere ) is probably the best way of doing this.
This is because if you want each player to collect 4 dolls and its server sided then 1 player could collect all the dolls and the door would open for everyone, so the door needs to open client side.
So have it so click detectors in the doll, once clicked +1 to the IntValue, have a script that is
function OpenDoor()
--Code for opening the door however you want
end
IntValue.Changed:connect(function()
if IntValue.Value == 4 then
OpenDoor()
end
end)
If you want it so a group has to collect the dolls:
Personally I would do it in the server. Have another folder called players with ObjectValues named after the players (With the value being the players character)., and do the same thing as before but the int value is inside the players object value.
Idk this is just the way i would do it.
The scripts are just example, and you will have to tweak them a bit. But the first script should be put in serverscript service and the 2nd in a doll or something. But you have to tweak them so they work like the 2nd script needs to be made so that it works with a click detector.
so how would i script adding 1 to the value and where would i put that?
also im assuming that the script you’re showing goes into the door, correct?
local doll2 = game.Workspace.dolls.CHAIR2doll
local doll3 = game.Workspace.dolls.CHAIR3doll
local doll4 = game.Workspace.dolls.CHAIR4doll
local click = script.Parent.ClickDetector
local open = script.Parent.Script
local locked = game.ServerStorage.locked
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local dolls = Instance.new("IntValue")
dolls.Name = "Dolls"
dolls.Parent = leaderstats
local playerUserId = player.UserId
local data = playerData:GetAsync("Player_"..playerUserId)
if data then
dolls.Value = data['Dolls']
else
dolls.Value = 0
end
end
like this?
Ye but why did you need to define all the dolls? that isnt needed until the second script.
yeah i had that from before and i didnt delete it sorry LOL
- so have the dolls, in a folder, in the workspace
- Insert a click detector into each doll (I’m assuming there Models/MeshParts)
- have this code in StarterPlayer Scipts (can be in a GUI if you want any part of this script shown to the player e.g Dolls collected could be displayed in a screen GUI but youll have to make those edits yourself)
function OpenDoor ()
--Door Opening script
end
local DollsCollected = 0
local Dolls = game.Workspace.Dolls:GetChildren()
for i = 1,#Dolls do
Dolls[i]:FindFirstChildWhichIsA("ClickDetector").MouseClick:Connect(function()
if DollsCollected < #Dolls then
DollsCollected +=1
Dolls[i]:Destroy() -- Wont destroy doll in server, only for players client
if DollsCollected == #Dolls then
OpenDoor()
end
end
end)
end
Dolls:Destroy() only deletes the dolls for the player not in the game so dont worry about other players not being able to do this (aslong as this script is a local script)
(This way is better than my last post because using Value Objects is exploitable and also unnecessarily complicated)
i’m confused about the second one. (ill send what i have so far at the end)
i still dont rlly know where to put it because if it goes into one doll, idk how to identify the other dolls (if that makes sense?) also i have a script for clicking the doll already, would i add it to that?
yes so i actually already have individual scripts for the dolls in starterGUI which make them disappear and some other details like a jumpscare. the dolls are also in a folder. does this same script work if each doll has its own individual script for making it disappear when clicked?
I would have to see the script
the script from one of the dolls?
Any scripts that do anything to the dolls really,
local doll = game.Workspace.dolls.doll1.ClickDetector
local doll2 = game.Workspace.dolls.CHAIR1doll
local sound = doll.Parent.Sound
local one = game.Lighting.one
local two = game.Lighting.two
local number = game.Workspace.numberSeven.seven
one.Enabled = false
two.Enabled = false
number.Transparency = 1
doll.MouseClick:Connect(function()
sound:Play()
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
one.Enabled = true
wait(.03)
one.Enabled = false
wait(.03)
two.Enabled = true
wait(.03)
two.Enabled = false
wait(.03)
for i,v in pairs(workspace.dolls.doll1:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = 1
if v.Transparency == 1 then
doll:Destroy()
end
for i,v in pairs(workspace.dolls.CHAIR1doll:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = 0
number.Transparency = 0
end
end
end
end
end)
heres the script for doll number one
Yeah scrap that, Just let me know the desired effect you want with the jump scare/lighting effects and ill type it up really quick. cause that ones a little bit messy and may pose problems later in you game development