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

How to make a click detector run a function only for a group?

Asked by 5 years ago
Edited 5 years ago

So I have been recently trying to make a click detector that make a part become semi transparent only for a group. I am able to do this for everyone but not for just a group. I tried this:

local player = game.Players.LocalPlayer
local groupId = 3793549


function test()
    if player:IsInGroup(groupId) then

        game.Workspace.Part.CanCollide = false
        game.Workspace.Part.Transparency = 0.5
        wait(3)
        game.Workspace.Part.CanCollide = true
        game.Workspace.Part.Transparency = 0
    end
end

game.Workspace.Part.ClickDetector.MouseClick:Connect(test) 

I put the script in game.StarterPlayer.StarterPlayerScripts . Any advice? Also the script needs to affect everyone. It just needs to activate only from group members.

0
playerAdded instead of localplayer in a regular script inside the block maybe??? greatneil80 2647 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

That current script is a LocalScript. Any code in that local script will only execute on and for the player running the script. My advice would be to have a RemoteEvent listen for the OnClientEvent event. The event will set the transparency to 0.5 and do the other things. Then you'd check if the player who clicked the part is in the group, and if they are, loop through the players on the server, check if they're in a group, and calling FireClient on said players. That would fire OnClientEvent, showing the part changes to the group members.

Hope this helps!

Ad

Answer this question