**I'm currently making a Simulator game with a special Kill Door system. Through killing monsters you will obtain kills from the leaderstats and if you reached the 100 kills the door will unlock and save itself. But i don't really know where i made the mistake
If i am in roblox studio the door will unlock and save itself, but in the client the door will also unlock if i reach the 100 kills, but when i rejoin the door isnt gone while i have 100 kills.
Another problem.. When a player in the client reached the 100 Kills, the door will not only unlock for him but also for everyone else in the client. How do i fix this problem **
--// Services
local Players = game:GetService("Players")
--// Variables
local door = game.Workspace.FirstDoor
--// Main Code
local function CheckKill(val) if val >= 100 then door:Destroy() else print("Not enough") end end
Players.PlayerAdded:Connect(function(Player) local leaderstats = Player:WaitForChild("leaderstats") local killStat = leaderstats:WaitForChild("Kills") CheckKill(killStat.Value) leaderstats.Kills.Changed:Connect(function(Value) CheckKill(Value) end) end)
A couple things here. It appears as though you're missing a way to save kills. Do this with something called a Datastore! Read about them here cause you'll learn more: https://developer.roblox.com/en-us/articles/Data-store
Also consider destroying the door on the local side of things from a local script.
If you implement a datastore, this should solve your issues!
Now, I am fairly new to scripting, but it seem like when the door destroys, it is being replicated to EVERYBODY.
I am guessing that you want a object to be replicated only to a specific player. I recommend using a LocalScript so you can replicate only a specific object to a specific player.
Just my 2 cents.