#MouseButton1Click doesn't work

94 messages · Page 1 of 1 (latest)

arctic jackal
#

@hoary yacht here

#

if it doesnt fix

#

nope

#

Tell me an exact location for the script

#

like game.ScreenGui.example

#

just fix it

#

if it doesnt work

#

doesnt work at all

#

look

#

using remoteevent?

#

ok

#

i read

#

cant lisen dont have tts

#

warn("ScreenGui or BadgeAwardButton not found.")

#

popped up

analog panther
#

wth

arctic jackal
#

Please, help?

analog panther
#
local click = game.Players.LocalPlayer.PlayerGui:FindFirstChild('2D')
local click2 = click.MainFrame.Buttons:WaitForChild('Play')
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

--[ LOCALS ]--
local PlayedBadge = 2146323716

--[[ UI FUNCTION ]]--
local function AddUI(pl)
    local PlayerGui = pl:WaitForChild("PlayerGui")
    local Frame = game.StarterGui.FirstTimePlayingGui:Clone()
    Frame.Parent = PlayerGui
    Frame.Enabled = true
end

local function addBage9(player)

    local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, PlayedBadge)
    if success then
        if badgeInfo.IsEnabled then
            if not BadgeService:UserHasBadgeAsync(player.UserId,PlayedBadge) then
                AddUI(player)
                BadgeService:AwardBadge(player.UserId,PlayedBadge)
            else
                print("player owns badge")
            end
        else
            print("badge is disabled")
        end
    else
        print("error getting badge info")
    end
end

--[ FUNCTIONS ]--
click2.MouseButton1Click:Connect(function()
    addBage9(game.Players.LocalPlayer)
end)
arctic jackal
#

lifesaver

#

StarterGui.FirstTimePlaying:5: attempt to index nil with 'PlayerGui' error pops up at first line

#

@analog panther

#

Sorry for ping

analog panther
#

copy paste the code again

#

I edited it.

arctic jackal
#

The names are correct or do I need to edit something?

sly hare
#

bro what is happening in here

#

why is there 60 messages for mousebutton1click

arctic jackal
#

Because it doesn't work

sly hare
#

send script again

analog panther
#
game.Players.LocalPlayer

Add this to the addBage9 parenthesis at the mousebutton1clickfunction.

arctic jackal
#

To double check the script and the gui are inside game.StarterGui

arctic jackal
sly hare
#

alright nvm then

lapis olive
#

😭

arctic jackal
#

Same output

#

Nothing

lapis olive
#

Click on localscript -> remote event to serverscript -> serverscript gives badge

arctic jackal
#

Yes

#

That is a very good idea

#

Told that to Carolien

#

Said it won't work.

lapis olive
#

That is not an idea

#

It is the way

analog panther
#

Yes, you should make sure that the script and the GUI are inside game.StarterGui. However, you should also note that the script will not run in game.StarterGui because it is a server script and StarterGui is a client-only service. You should move the script to ServerScriptService or another server-side location. Alternatively, you can make the script a local script and keep it in StarterGui, but then you will need to use a remote event to communicate with the server and award the badge.

arctic jackal
lapis olive
#

Tutorial

#

That's all that needs to be said

arctic jackal
#

Of course

#

crims I can check in a local script if a player has a badge yes?

lapis olive
#

No

#

Badges are serverside

analog panther
#

To use the remote event, you need to create one in a shared location, such as ReplicatedStorage. Then, you need to write two scripts: one for the sender and one for the receiver. The sender script will call the FireServer method on the remote event, passing any arguments you want to send. The receiver script will connect a function to the OnServerEvent property of the remote event, which will run whenever the event is fired. The function will receive the arguments sent by the sender, as well as the player who fired the event.

Create a remote event named "AwardBadge" in ReplicatedStorage

Local Script in starterplayerscripts.



local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local AwardBadge = ReplicatedStorage:WaitForChild("AwardBadge")
local PlayedBadge = 2146323716

local function checkBadge()
    local player = Players.LocalPlayer
    if not BadgeService:UserHasBadgeAsync(player.UserId, PlayedBadge) then
        AwardBadge:FireServer(PlayedBadge)
    end
end

checkBadge()
#

Server script in serverscriptservice

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeService = game:GetService("BadgeService")

local AwardBadge = ReplicatedStorage:WaitForChild("AwardBadge")

local function awardBadge(player, badgeId)
    if BadgeService:GetBadgeInfoAsync(badgeId).IsEnabled then 
        BadgeService:AwardBadge(player.UserId, badgeId)
    end
end

AwardBadge.OnServerEvent:Connect(awardBadge)
#

This is an example though, so you will need to implement it in your system, yourself.

arctic jackal
#

Ok

#

Works like this, no?

lapis olive
#

Yes

#

And in between green and blue box is a remoteevent

analog panther
#

yes

lapis olive
#

Fires from the localscript, green box, to the serverscript, greenbox

#

I would do all checks on serverside

arctic jackal
#

It is more safe, I know

lapis olive
#

Yes

sly hare
#

yall still working on this

#

my man made an illustration

arctic jackal
#

Yo, come help if so smart

sly hare
#

i didnt said i was smart

analog panther
#

💀

sly hare
#

but damn

#

either this rly difficult

#

or yall not smart

#

i said send code and u ignored me

analog panther
analog panther
arctic jackal
#

And connect everything with RemoteEvents?

sly hare
#

what are you trying to connect

arctic jackal
#

So look at the ilustration

#

I got it now

#

It's fixed

analog panther
analog panther
arctic jackal
#

I got it now

analog panther
#

lets gooo

arctic jackal
#

Just gotta use RemoteEvents

analog panther
#

lol

arctic jackal
#

@analog panther If still available, can you help me with an older issue?

lapis olive
arctic jackal
#

First thread was a guy being just dumb and not helping me

low sonnet
#

How do I make it that when a player presses L after 15 seconds their health and max health increases by 900000 and their max health and health decreases by 969 every second and this lasts until the player dies, make a modern script.