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

Help with Owner only door?

Script 1

script.Parent.Head.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			local ownstycoon = cashmoney:FindFirstChild("OwnsTycoon")
			if ownstycoon then				
				if ownstycoon.Value == false then
					if script.Parent.Parent.Parent.Owner.Value == nil then
						if hit.Parent:FindFirstChild("Humanoid") then
							if hit.Parent.Humanoid.Health > 0 then
								script.Parent.Parent.Parent.Owner.Value = player
								ownstycoon.Value = true
								script.Parent.Name = player.Name .. "'s Tycoon"
								script.Parent.Head.Transparency = 0.6
								script.Parent.Head.CanCollide = false
								player.TeamColor = BrickColor.new(script.Parent.Parent.Parent.Name)
							end
						end
					end
				end	
			end
		end
	end
end)

Script 2

script.Parent.Head.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if script.Parent.Head.Transparency == 0.6 then
		if player.Name ~= script.Parent.Parent.Parent.Owner.Value then
			player.Character:FindFirstChild("Humanoid").Health = 0
		end
	end 
end)

19:54:07.396 - Workspace.Tycoons.Bright blue.Gate.Touch to claim Ownership:6: attempt to index local 'player' (a nil value) 19:54:07.396 - Stack Begin 19:54:07.397 - Script 'Workspace.Tycoons.Bright blue.Gate.Touch to claim Ownership', Line 6

I have these 2 scripts inside a model. I am using Berezas tycoon kit, and the first script is his and the second is mine. I'm trying to get it so when a person who is not the owner walks into the door it will kill them, but this dosent work.

1 answer

✓ Accepted answer

This is a tricky mistake. Your problem is that the Transparency property is a float value, meaning that it's not exactly what you set it to.. so if you set it to .6, it can be something like .60000112 or something like that.

So, because of this difficulty, the condition will never pass because it's looking for the Transparency to be EQUAL to .6, not around.

So to fix? Make a grouped condition. Less than 7 and greater than 6.

local hed = script.Parent.Head

hed.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if hed.Transparency > 0.6 and hed.Transparency < .7 then
		if player.Name ~= script.Parent.Parent.Parent.Owner.Value then
			player.Character:FindFirstChild("Humanoid").Health = 0
		end
	end 
end)

5 comments

0

This just kills everyone who enters it

0

Well then I guess no one's name is equal to the Owner.Value :P

0

i fixed it, but now it just lets everyone through again

0

nvm, it still kills the player. It definitely has an owner, cause I checked the workspace on server mode.

0

editted my answer with output

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