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

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

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

How do I fix this?

game.Workspace.ElevatorAccess.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	local Group = 5762728
	local Rank = game.ReplicatedStorage.Rank
	local gamepass = 0
	local MS = game:GetService("MarketplaceService")
	if hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)then
		if game:GetService("Players")[hit.Parent.Name]:IsInGroup(Group) and game:GetService("Players")[hit.Parent.Name]:GetRankInGroup(Group) >= Rank then
			local Ui = workspace.ElevatorAccess.ScreenGui
			local Ui2 = Ui:Clone()
			Ui2.Name = "TP"
			Ui2.Parent = plr.PlayerGui
		elseif MS:UserOwnsGamePassAsync(plr.UserId, gamepass) then
			local Ui = workspace.ElevatorAccess.ScreenGui
			local Ui2 = Ui:Clone()
			Ui2.Name = "TP"
			Ui2.Parent = plr.PlayerGui
		else
			local frame = workspace.ElevatorAccess.SurfaceGui.Frame
			frame:TweenPosition(UDim2.new(0, 0,0, 0))
			wait(2.5)
			frame:TweenPosition(UDim2.new(-1, 0,0, 0))
		end
	end
end)

1 comment

0

Should be local Rank = game.ReplicatedStorage.Rank.Value

3 answers

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

game.Workspace.ElevatorAccess.Touched:Connect(function(hit)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    local Group = 5762728
    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
    local gamepass = 0
    local MS = game:GetService("MarketplaceService")
    if hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)then
        if game:GetService("Players")[hit.Parent.Name]:IsInGroup(Group) and game:GetService("Players")[hit.Parent.Name]:GetRankInGroup(Group) >= Rank then
            local Ui = workspace.ElevatorAccess.ScreenGui
            local Ui2 = Ui:Clone()
            Ui2.Name = "TP"
            Ui2.Parent = plr.PlayerGui
        elseif MS:UserOwnsGamePassAsync(plr.UserId, gamepass) then
            local Ui = workspace.ElevatorAccess.ScreenGui
            local Ui2 = Ui:Clone()
            Ui2.Name = "TP"
            Ui2.Parent = plr.PlayerGui
        else
            local frame = workspace.ElevatorAccess.SurfaceGui.Frame
            frame:TweenPosition(UDim2.new(0, 0,0, 0))
            wait(2.5)
            frame:TweenPosition(UDim2.new(-1, 0,0, 0))
        end
    end
end)

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:

        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:

    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.

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