1.I am trying to make text appear on a textbutton once the player clicks the button. Nothing happens.
Current code:
serverscript
game.StarterGui.ScreenGui.Frame.TextButton.MouseButton1Click:Connect(function(plr)
script.Parent.Clicked:FireClient(plr)
end)
localscript
local rarity = {"common", "uncommon"}
local txtbutton = script.Parent.TextButton
local function onClickedFire()
txtbutton.Text = rarity[math.random(1, #rarity)]
end
game.ReplicatedStorage.Events.Clicked.OnClientEvent:Connect(onClickedFire)
Along with that, I am trying to add an accessory to the player once they get a certain rarity, here’s my concept, however nothing happens and nothing chnages.
local rarity = {"common", "uncommon"}
local txtbutton = script.Parent.TextButton
local function onClickedFire()
local player = game.Players.LocalPlayer
local ranrarity = rarity{math.random(1, #rarity)}
if ranrarity == "common" then
print("common")
game.ReplicatedStorage.Hats.Tophat.Parent = player.Character
elseif ranrarity == "uncommon" then
print("uncommon")
end
end
game.ReplicatedStorage.Events.Clicked.OnClientEvent:Connect(onClickedFire)
if this is a local screen ui interface, why are you using the starterGui to define the button? wouldn’t it just already be on the players screen in their playergui? it seems to me like you should be able to do this code without using a remote event, just look for when the button is clicked in the local script.
Like @StrangPan said it should be a localscript so you should use playergui not startergui
local playerGui = game.Players.LocalPlayer.PlayerGui
playerGui.ScreenGui.Frame.TextButton.MouseButton1Click:Connect(function(plr)
end)
since you can’t run :FireClient on a localscript, you should fire it to the server FYI the accessory being added on client won’t work, so it should be on the server instead too
Localscript:
local rarity = {"common", "uncommon"}
local txtbutton = script.Parent.TextButton
local function onClickedFire()
txtbutton.Text = rarity[math.random(1, #rarity)]
end
local playerGui = game.Players.LocalPlayer.PlayerGui
playerGui.ScreenGui.Frame.TextButton.MouseButton1Click:Connect(function(plr)
onClickedfire()
script.Parent.Clicked:FireServer()
end)
Server:
local clickedEvent -- define where the event is
local rarity = {"common", "uncommon"}
local function onClickedFire(player)
local ranrarity = rarity{math.random(1, #rarity)}
if ranrarity == "common" then
print("common")
game.ReplicatedStorage.Hats.Tophat.Parent = player.Character
elseif ranrarity == "uncommon" then
print("uncommon")
end
end
clickedEvent.OnServerEvent:Connect(function(player)
onClickedFire(player)
end)
I suppose your server script is inside starter gui if so then the script won’t run
What you should do is add a local script inside of your button and fire the remote event when it’s clicked to choose the rarity in the server since hacker can change local script it’s better to do it in the server then fire the remote event to client with the rarity that has been choosen. (Also to detect if a button is clicked use .Activated)