I need help with my scripts

i would love your help but i really feel like i’m not explaining it properly and i really just need something simple that i can understand.

EXACTLY. That is how I felt. Im making this script right now and i will try to explain it the best I can. And I can tell you want you need to learn to make it yourself later on.

alright thank you so much :))))

Alright I got a script, isn’t to complicated I will edit this post with the script stuff in a second. Sorry it took so long.

alright our script to make a leaderboard or leaderstats

-- Remmber to enable API services in gamesettings.security for data storage to work!
-- Put this in serverscriptservice



local DataStoreService = game:GetService("DataStoreService")  --this is getting the the service for the data store(DataStoreService is the service for storing data)
local playerData = DataStoreService:GetDataStore("playerData") --we get the players service since players are a service and need to be defined


local function onPlayerJoin(player)         --our function

	local leaderstats = Instance.new("Folder")  -- were making a folder to store our data
	leaderstats.Name = "leaderstats"    --folder is called leaderstats
	leaderstats.Parent = player         --the folder's parent is the player

	local souls = Instance.new("IntValue")   -- im using souls as an example, for our intvalue, or the value what were going be storing our numbers under
	
	souls.Name = "Dolls"   -- it will say Dolls on the leaderboard
	souls.Parent = leaderstats   -- The instance's parent


	local playerUserId = player.UserId   --Players name
	local data = playerData:GetAsync("Player_"..playerUserId)  --Players data

	if data then   
		souls.Value = data['Dolls']    --gives dolls a value

	else
		souls.Value = 0   --Sets the data to 0
		
	end
end



game.Players.PlayerAdded:Connect(onPlayerJoin)   --Defines onPlayerJoin, when a player joins it connects that to our function defining what onPlayerJoin means

Now our script for the dolls

--put this is the doll
--You can then duplicate the doll

local part = script.Parent   --part, our our doll

function OnTouch()    --our function 
	local playersService = game:GetService('Players')    -- emmber players isa service and we have to get that
	local player = playersService:FindFirstChildOfClass('Player')    --Were finding the player
	local leaderstats = player:FindFirstChild("leaderstats")   --the leaderstats we made 
			local souls = leaderstats:FindFirstChild('Souls') --Our dolls number
				souls.Value = souls.Value + 1 --Adds 1 to our doll count
				part.Transparency = 1   --you cant see the doll
				part.CanCollide = false --you can move through the doll
	            part.CanTouch = false   --our function cant be triggered again 

end
	


part.Touched:Connect(OnTouch)    -- connecting the function, defining what OnTouch means

Key terms tyou should look up on the developer hub to learn:

-Services
-Instances
-DataStoreService
-API Services
-Player Service
-leaderstats

And ya, if you have any questions please ask!

Also note, in studio this will work but if you test it again the doll wont show up. idk why, I tried to change it but it didnt work. Though just know it works and i tested it.

ALSO ALSO NOTE I MADE THE SCRIPT THAT IF YOU COLLIDE WITH THE DOLL NOT CLICK IT. You can change it if you wish

hey just saw this! i’ll test it in a sec, thanks!

1 Like

is there any way to make it not appear on the leaderboard and still have the script run the same?

last thing, how do i use the leaderstats to identify when they’re all collected for the door script?

Sorry couldnt respond earlier, alright that shouldn’t be too hard I’ll do that later. But do you understand the scripts?

i believe so! and thank you, i’ll be out for a bit today but i’ll check when i get baclk

Ok here I have the script for the door. If you have any questions, please ask!

local part = script.Parent   --the door
local requiredDolls = 4     --we eed 4 dolls
local playersService = game:GetService('Players')    --Get the player service
local player = playersService:FindFirstChildOfClass('Player')    -- find the player clas
function onTouch()      --touch the part
	if player.leaderstats.Souls.Value >= requiredDolls then  -- if the leaderstats = the required amount of dolls
		part.Transparency = 1  --make the door transparent
		part.CanCollide = false --You can walk through the door
	end
end

part.Touched:Connect(onTouch)    --connects the funtion

where do i put the script again? also, does it work for a local script? (meant to ask this here sorry haha)

Put it in the door, and you cant use a local script. I suggest make the game 1 player, so you dont need to use local scripts that much. Also it would make it scarier.

its also sort of a hangout game, so it has to be more sadly. also i put it into the door and its in a local script, but it does not work.

make it a server script, and I had the vibe you were making a horror game lol. Also do you have 4 dolls in the leaderstats?

its weird its kind of a mix of both, but overall it cant be 1 player servers sadly. i do have it in leaderstats and the leaderstats work

So does it work or does it not? Put all my scripts in server scripts. And test it.

i can test it in a server script, but it has to be local because i need to only work for the specific player

wait hold on i have to switch some things around

Oh, so only a specific player can use it? next time tell me this before so I could work that in with my script.

no no im not saying it right lol i mean like it has to be local because only the people with the dolls can use it