I am currently working on an elevator game, and I want to make group rewards. However, it shows this error when I am using the IsInGroup() function for line number 5:
local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336
script.Parent.Touched:Connect(function(hit)
if not game.Players:FindFirstChild(hit.Parent.Name):IsInGroup(groupid) then
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
local plr = game.Players[hit.Parent.Name]
if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = plr.PlayerGui
end
end
elseif game.Players:GetPlayerFromCharacter(hit.Parent):IsInGroup(groupid) then
script.Parent.CanCollide = false
script.Parent.Transparency = 0.9
wait(3)
script.Parent.CanCollide = true
script.Parent.Transparency = 0.7
end
end)
So when the player has touched the part, the script will check if the player is in the group or not. If the player is not in the group, it will pop up a GUI. If the player is in the group, it will make it so that way the door’s CanCollide property is false.
Again, I am not sure how to fix this, since I have tried everything to fix it and it is still not working. If anyone can find any solution to this, please inform me of this. Any and all fixes are appreciated.
local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player and not Player:IsInGroup(groupid) then
if Player.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = Player.PlayerGui
end
elseif Player and Player:IsInGroup(groupid) then
script.Parent.CanCollide = false
script.Parent.Transparency = 0.9
task.wait(3)
script.Parent.CanCollide = true
script.Parent.Transparency = 0.7
end
end)
hit.Parent should be the character whenever the player touches the part, then from there I get the player using the game.Players:GetPlayerFromCharacter line. I have printed out hit.Parent, and it prints out my username which is the character.
local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
if not Player:IsInGroup(groupid) then
if not Player.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = Player.PlayerGui
end
else
script.Parent.CanCollide = false
script.Parent.Transparency = 0.9
task.wait(3)
script.Parent.CanCollide = true
script.Parent.Transparency = 0.7
end
end
end)
Try this for debugging, then send a screen shot of your output
local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
print("Player exists!")
if not Player:IsInGroup(groupid) then
print("Player is not in group")
if not Player.PlayerGui:FindFirstChild(GUI.Name) then
print("GUI not being shown")
GUI:Clone().Parent = Player.PlayerGui
end
else
print("Is in group")
script.Parent.CanCollide = false
script.Parent.Transparency = 0.9
task.wait(3)
script.Parent.CanCollide = true
script.Parent.Transparency = 0.7
end
end
end)