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.
Local scripts cannot run in Workspace. Put them in a place such as StarterPlayerScripts.
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()