Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I fix this House Owner Script since it won't work properly?

Basically, what this script is suppose to do is when the player joins there is a value that is created, but if the players name is what ever you want then it sets the value to true. For some reason though it does this for anyone who joins the game. I already tried it even with FE turned off (The game is Filtering Enabled.) I don't see why it is not working and already know when you create a value it automatically sets the value to false. But this is setting the value true for everyone even if the name is different. I already been working on this and searched online but can't find anything, is there something I am missing?

game.Players.ChildAdded:connect(onPlayerEntered)

function onPlayerEntered(newPlayer)
	--4697 Apt B Hawthorne 129st--
	local HouseOwned4697AptB = Instance.new("BoolValue")
	HouseOwned4697AptB.Name = "HouseOwned4697AptB"
	
	HouseOwned4697AptB.Parent = newPlayer
		if newPlayer.Name == "Sergiomontani10" or "Davontae555" then
		HouseOwned4697AptB.Value = true
	end
end



game.Players.ChildAdded:connect(onPlayerEntered)

Script is located in ServerScriptStorage as a Server Script.

This is the same thing

function onPlayerEntered(newPlayer)
	--Checks if u got a house--
	local IsAHouseOwner = Instance.new("BoolValue")
	IsAHouseOwner.Name = "IsAHouseOwner"
	
	IsAHouseOwner.Parent = newPlayer
		if newPlayer.Name == "Sergiomontani10" or "Davontae555" or "Draqqon" or "ClxppaThaDon" or "" or "" or "" then
		IsAHouseOwner.Value = true	
	end
end

Layout https://i.imgur.com/nJwGNzJ.png

Thank you for any help.

1 answer

✓ Accepted answer

Ok so here we go:

-- first I suggest that you have a table of the names that you want to work
local nameTable = { "Sergiomontani10", "Davontae555", "Draqqon", "ClxppaThaDon"}
-- then let's create the playeradded event
game.Players.PlayerAdded:Connect(function(newPlayer) -- connect is deprecated use Connect instead 

also I am just gonna use an Anonymous function for the player added event

local nameTable = { "Sergiomontani10", "Davontae555", "Draqqon", "ClxppaThaDon"}
game.Players.PlayerAdded:Connect(function(newPlayer) 
	local isAHouseOwner = Instance.new("BoolValue") -- it is general practice to have the first word in your variable not be capitalized
	isAHouseOwner.Name = "IsAHouseOwner" 
	isAHouseOwner.Parent = newPlayer
	for i,v in pairs(nameTable) do -- a loop which goes through the nameTable
		if v == newPlayer.Name then -- if the players name is on the list then change the value
			isAHouseOwner.Value = true
		else -- this is here just in case. You don't have to do it.
			isAHouseOwner.Value = false
		end
	end
end)

Hope this helps. Comment below my answer if you have anymore questions. Have a great day scripting and good luck!

2 comments

0

Thanks man that worked really well. Im going to try to learn how to use in pairs

0

No problem

This discussion is preserved as it was. New answers, comments, and votes are closed.