So, I have an output of "LocalScript:8:attempt to compare Instance and number
How do I fix this?
01 | game.Workspace.ElevatorAccess.Touched:Connect( function (hit) |
02 | local plr = game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) |
03 | local Group = 5762728 |
04 | local Rank = game.ReplicatedStorage.Rank |
05 | local gamepass = 0 |
06 | local MS = game:GetService( "MarketplaceService" ) |
07 | if hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then |
08 | if game:GetService( "Players" ) [ hit.Parent.Name ] :IsInGroup(Group) and game:GetService( "Players" ) [ hit.Parent.Name ] :GetRankInGroup(Group) > = Rank then |
09 | local Ui = workspace.ElevatorAccess.ScreenGui |
10 | local Ui 2 = Ui:Clone() |
11 | Ui 2. Name = "TP" |
12 | Ui 2. Parent = plr.PlayerGui |
13 | elseif MS:UserOwnsGamePassAsync(plr.UserId, gamepass) then |
14 | local Ui = workspace.ElevatorAccess.ScreenGui |
15 | local Ui 2 = Ui:Clone() |
if game:GetService("Players")[hit.Parent.Name]:IsInGroup(Group) and game:GetService("Players")[hit.Parent.Name]:GetRankInGroup(Group) >= Rank then
You see, what this is checking is if the player is in the group. You're ALSO checking if their rank is above the set rank. This is redundant, if the player is NOT in the group, their rank is 0
. So you can remove the IsInGroup
function from your code.
The main issue in your code is...
You're setting the Rank
variable to be the IntValue object, rather than it's value. Replace Line 4
with this code:
local Rank = game.ReplicatedStorage.Rank.Value
This should fix it all.
Try to do this
01 | game.Workspace.ElevatorAccess.Touched:Connect( function (hit) |
02 | local plr = game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) |
03 | local Group = 5762728 |
04 | local Rank = game.ReplicatedStorage.Rank.Value ----You forgot to add in a value and Make sure the Rank is a number or int value or string |
05 | local gamepass = 0 |
06 | local MS = game:GetService( "MarketplaceService" ) |
07 | if hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then |
08 | if game:GetService( "Players" ) [ hit.Parent.Name ] :IsInGroup(Group) and game:GetService( "Players" ) [ hit.Parent.Name ] :GetRankInGroup(Group) > = Rank then |
09 | local Ui = workspace.ElevatorAccess.ScreenGui |
10 | local Ui 2 = Ui:Clone() |
11 | Ui 2. Name = "TP" |
12 | Ui 2. Parent = plr.PlayerGui |
13 | elseif MS:UserOwnsGamePassAsync(plr.UserId, gamepass) then |
14 | local Ui = workspace.ElevatorAccess.ScreenGui |
15 | local Ui 2 = Ui:Clone() |
It is giving that error because on line 8 you are trying to compare the group rank which is a number to the "instance" which is probably a IntValue. to fix this you have to compare the rank number to the IntValues actual Value(the rank istance in replicatedStorage). so instead what you would do on line 8 is:
1 | if game:GetService( "Players" ) [ hit.Parent.Name ] :IsInGroup(Group) and game:GetService( "Players" ) [ hit.Parent.Name ] :GetRankInGroup(Group) > = Rank.Value then |
or you could do this on line 4:
1 | local Rank = game.ReplicatedStorage.Rank.Value |
either of them work but dont use both of them or you will get an error trying to get the Value of the Value. anyway i hope this helped you.