Hi, for the past few hours I’ve been trying to make a script that checks if you own a game pass and if you do, check if a mode is enabled. So far, everything’s working out except the script that checks if the mode is enabled. Here’s the script:
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local humanoid = hit.Parent.Humanoid
local PassId = 000 --- I put my game pass id here.
if plr then
local name = plr.Name
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, PassId) then
if game.Players[plr.Name]:FindFirstChild("ez").Value == true then
else
humanoid.Health = 0 ---Kills you no matter what for some reason.
end
end
end
end)
To show where the boolvalue is, here’s a screenshot:
What’s also weird is, even though the value is true, it kills:
I looked over the dev forum before posting, just in case someone found the solution before me. f you somehow know what the problem is, please let me know. Thanks.
Why are you indexing a player’s name in the Players service when you already called the player’s instance? Couldn’t you just simply use your variable that you defined plr?
What’s really the issue here? Did you get any errors?
Also, using HumanoidObject.Health = 0, will, of course, kill the player, no matter what. You can use HumanoidObject:TakeDamage(#), which can’t do damage to a Humanoid, if it has ForceField.
Sorry, I might’ve confused you a little. The script is only supposed to kill if the value is false or you don’t own the game pass. It kills no matter what. Also, there’s no errors.
Try using if plr:WaitForChild("ez").Value == true then, since, firstly, you already have a PlayerObject, and secondly, we use :WaitForChild(), which will yield until it finds the instance with given name.
The part is being touched by a part in an accessory then, not a body part in the character.
I agree with this, no point in trying to index hit if you are going to do this.
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local humanoid = plr and plr.Character and pl.Character:FindFirstChild("Humanoid")
if not humanoid then return end
This would be a better and wouldn’t error if an accessory hit or something like that.
Like ijmod said, use the plr variable for this. Don’t bother using FindFirstChild if you aren’t going to check if it exists, just directly index.
script.Parent.Touched:Connect(function(hit)
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChild("ez").Value == true then
--your code here
end
end)
local PassId = 000
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local name = plr.Name
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") -- find a humanoid instance in the player's character
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, PassId) then
local ez = plr:FindFirstChild("ez") -- find the boolvalue
if ez then -- check to see if it's nil
if ez.Value then
-- code here
else
if humanoid then -- like FindFirstChild, check to see if the humanoid exists
humanoid.Health = 0
end
end
end
end
end
end)
you can make a system for which when a player joins and they own a gamepass, it enables it (from the server)
or
local PassId = 000
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local name = plr.Name
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, PassId) then
local ez = plr:FindFirstChild("ez")
if ez then
if not ez.Value then ez.Value = true end -- enables it, if it isn't enabled
if ez.Value then
else
if humanoid then
humanoid.Health = 0
end
end
end
end
end
end)