Whats up peeps, I would like to inform you all that I am a very new scripter.
But I am trying to make a click detector group wall, it seems to be that nothing is registering. Below is my code
local part = script.Parent
local gid = 11497677 -- group id here
function onClicked()
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(gid) then
part.BrickColor.Color = Color3.new(0.25098, 0.658824, 0.12549)
part.CanCollide = false
print('Ran')
part.BrickColor.Color = Color3.new(0.87451, 0, 0)
end
end)
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
if someone could help that would be great
2 Likes
What type of script is this? Server or local script?
This is a server script, LifeDigger
I think the issue could be that u are doing game.Players.PlayerAdded:connect.
That then awaits for a player to join the server I believe.
Put a print right at the start of the function before the game.Players.PlayerAdded to see if it runs the print before u do any of that stuff.
Ah, so the print came back. How would I change the first part?
Why are u doing this part? Is it so u can then check to see if the user is in the group?
Correct, I am trying to check if the player is in the group.
I was reviewing the Player:IsInGroup section in the developer.roblox.com website and it said to put that.
The reason why it says that is cuz of how the code on there page works. It is diffrent in ur case cuz u want it at a call on the function not when a user joins.
Wait a min i wanna test something which i think should fix the issue
Get rid of this and the line at the end.
Also change this to function onClicked(plr)
What you did was create an event listener for when the player gets added, however the player is already in the game. The MouseClick
event for ClickDetector passes the plr
parameter automatically.
Ok so this should work;
local part = script.Parent
local groupID = 6559630
function onClicked(PlayerClicked)
if PlayerClicked:IsInGroup(groupID) then
print('Ran (user in group)')
else
print("User is not in group")
end
end
part.ClickDetector.MouseClick:Connect(onClicked)
You just got to put the plr in the paramter of the functon onClicked cuz one of the paramters which it sends from the mouseclick event thing is the plr who clicked it.
Don’t take my code exactly cuz it got one of my group ID’s in it and u dont need the else and u need to add the diffrent stuff inside but take this as a refrence code