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

BindableEvent fired, but isn't being received? [SOLVED]

Asked by 4 years ago
Edited 4 years ago

Hello, I'm currently making it so a PlayerGui is changed via BindableEvent (as it's client to client), the BindableEvent does fire, but the other local script doesn't receive it.

Here's my firing local script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local rewardchange = game.ReplicatedStorage:WaitForChild("RewardChange")

local function mouseclick()
    rewardchange:Fire()
    print("Fired")
end

game.Players.LocalPlayer.PlayerGui.ScreenGui.Mainframe.PremiumPack.MouseButton1Down:Connect(mouseclick)

It's parent is StarterGui.

The receiving local script is in Workspace, and here it is:

local rewardgui = game.Players.LocalPlayer.PlayerGui.RewardGui
local button = game.Players.LocalPlayer.PlayerGui.ScreenGui.Mainframe.PremiumPack
local rewardchange = game.ReplicatedStorage:WaitForChild("RewardChange")

rewardchange.Event:Connect(function()
    print("received")
    local list = {"narahero","narahero","killerhero","wethero"}
    local card = list[math.random(#list)]
    if card == "narahero" then
        rewardgui.NaraHero.Visible = true
        rewardgui.NaraHeroDescription.Visible = true
        rewardgui.NaraHeroHolder.Visible = true
        rewardgui.NaraHeroName.Visible = true
        print("It's good")
    elseif card == "killerhero" then
        rewardgui.KillerHero.Visible = true
        rewardgui.KillerHeroDescription.Visible = true
        rewardgui.KillerHeroHolder.Visible = true
        rewardgui.KillerHeroName.Visible = true
        print("It's good")
    elseif card == "wethero" then
        rewardgui.WetHero.Visible = true
        rewardgui.WetHeroDescription.Visible = true
        rewardgui.WetHeroHolder.Visible = true
        rewardgui.WetHeroName.Visible = true
        print("It's good")
    end
    button.Parent.Visible = false
end)

The way I know it doesn't receive is cause 'received' doesn't print, any help would be appreciated.

0
i updated my answer to include ihatecar's answer. should be better for when people google and find this thread royaltoe 5144 — 4y
0
since it has multiple troubleshooting options royaltoe 5144 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Local scripts cannot run in Workspace. Put them in a place such as StarterPlayerScripts.

Ad
Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

A few things to look out for:

1) Make sure it's not your mouse clicked function: print out in mouse click to make sure you're actually calling the function.
2) Let your event functions connect before you fire the event function. If you fire too early or have something like a while loop infront of the event function, the code will never run.`
3) Make sure you have an event called RewardChange in the replicated storage. You might have a case of infinite waiting for the bindable event.

4) Make sure your local scripts are somewhere they can be run like starterCharacterScripts

I tried myself with this code, and it seemed to work given all those conditions:

LocalScript1

local rewardchange = game.ReplicatedStorage:WaitForChild("RewardChange")

rewardchange.Event:Connect(function()
    print("received")
end)

LocalScript2

local rewardchange = game.ReplicatedStorage:WaitForChild("RewardChange")

wait(3) --gives some time for the function in LocalScript1 to load

rewardchange:Fire()

Answer this question