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

PlayerAdded Not working How Do I Fix This?This Should Detect players When They Join

Asked by 3 years ago
Edited 3 years ago

Hey There!Im Sorry If Im getting Too Many Errors Lately But Im Just New So When The Script Gets 2 The Line Of script Containing My "PlayerAdded" Script The Whole script Stops Like When I play The Game And I Press The Button Nothing Works Tried Even printing After The PlayerAdded Here Is The Portion Of The Code: (keep In mind I Dont Have Any Variables Cointaning "Plr" So Yea)

Players.PlayerAdded:Connect(function(player)
    print("PlayerJoined")
button.MouseButton1Click:Connect(function()--when a player presses the button in left click
        script.Parent.Parent.Visible = false-- should invis the frame
        print("Pressed")-- when a player presses the button then it will print out "Pressed"
    end)
end)

Thanks!

0
First of all, you need game.Players.PlayerAdded instead of just Players. I also recommend you do MouseButton1Clicks on the Local Side, not the Server. LennyPlayzYT 269 — 3y
0
Oh ok tnx Rgboffical_yt 40 — 3y
0
But i have a pproblem if i do it on another script then it wont work beaacuse i need the player in the playeradded Rgboffical_yt 40 — 3y
0
Another thing is i have alreeady defined player so i dont need Game Rgboffical_yt 40 — 3y
0
I provided The Full script So You dont get More Confused, Btw Its A Normal Script Rgboffical_yt 40 — 3y

2 answers

Log in to vote
1
Answered by
VAHMPIN 277 Moderation Voter
3 years ago
Edited 3 years ago

Have you defined "button" also, i'd recommend using WaitForChild

local S = game.Players.LocalPlayer.PlayerGui.GUINAME.FRAMENAME:WaitForChild("Nameofbutton")

-- after its done

S.MouseButton1Down:Connect(function()
-- script
end)
0
Ok tnx.but the variables work the thing is playeraddded does not work Rgboffical_yt 40 — 3y
0
I provided The Full script So You dont get More Confused Rgboffical_yt 40 — 3y
0
btw its a Normal Script Rgboffical_yt 40 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

The Full Script Is Here:

--Variables--
local Players = game:GetService("Players")
local button = script.Parent-- gets the button
print("VariablesDone!")--prints "VariablesDone!"
--MainScript--
Players.PlayerAdded:Connect(function(plr)
    print("playerJoined")
button.MouseButton1Click:Connect(function()--when a player presses the button in left click
        script.Parent.Parent.Visible = false
        print("Pressed")-- when a player presses the button then it will print out "Pressed"
    end)
end)

ThankYou! HopeFully You Will Understand it Better now

Answer this question