I have a door lock, it checks if a value inside the player is above 250, if it is, it lets them in. It works fine. But inside, I have a kill brick which also checks if the value is above 250. It should only kill the player if their value is BELOW 250, but it still kills me even when my value is 255.
Normal script inside the kill brick:
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player:WaitForChild("GroupRank").Value >= 250 then
player.Character.Humanoid.ragdoll.Value = true
player.Character.Humanoid.Health = 0
game.ReplicatedStorage.Message:FireClient(player, "You shouldn't be in this room, it is for council members only!")
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player:WaitForChild("GroupRank").Value >= 250 then
player.Character.Humanoid.ragdoll.Value = true
player.Character.Humanoid.Health = 0
game.ReplicatedStorage.Message:FireClient(player, "You shouldn't be in this room, it is for council members only!")
end
end
end)
If you try put print(hit.Parent) it will not show your character it show the body of the character so game.Players:GetPlayerFromCharacter will not work
You can check whether what is hit is a player or not by using IsA() to check for a Humanoid Root Part.
In your case a good example would be,
if hit.Parent:IsA("Model") then
if hit.Parent:FindFirstChild("HumanoidRootPart") then
print("this is in fact a character model.")
else
print("This is not a character model.")
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent:IsA("Model") then
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player:WaitForChild("GroupRank").Value >= 250 then
player.Character.Humanoid.ragdoll.Value = true
player.Character.Humanoid.Health = 0
game.ReplicatedStorage.Message:FireClient(player, "You shouldn't be in this room, it is for council members only!")
end
end
end
end)