Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I thought it was right, I looked in the output and saw an error. How do I fix this?

Asked by
Comqts 6
4 years ago

So, I have an output of "LocalScript:8:attempt to compare Instance and number

How do I fix this?

01game.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 Ui2 = Ui:Clone()
11            Ui2.Name = "TP"
12            Ui2.Parent = plr.PlayerGui
13        elseif MS:UserOwnsGamePassAsync(plr.UserId, gamepass) then
14            local Ui = workspace.ElevatorAccess.ScreenGui
15            local Ui2 = Ui:Clone()
View all 25 lines...
0
Should be local Rank = game.ReplicatedStorage.Rank.Value Pupppy44 671 — 4y

3 answers

Log in to vote
1
Answered by
marfit 104
4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

Try to do this

01game.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 Ui2 = Ui:Clone()
11            Ui2.Name = "TP"
12            Ui2.Parent = plr.PlayerGui
13        elseif MS:UserOwnsGamePassAsync(plr.UserId, gamepass) then
14            local Ui = workspace.ElevatorAccess.ScreenGui
15            local Ui2 = Ui:Clone()
View all 25 lines...
Log in to vote
0
Answered by 4 years ago

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:

1if 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:

1local 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.

Answer this question