Is ther a way to make a function with var = #? like plr.leaderstats.blah = 4:Connect:Function()
Can you explain what you mean? It’s really hard to understand what you’re asking.
If you are referring to creating a variable that holds an event, then yes. However, if you want to store this event in some instance object just like you mentioned above with “plr.leaderstats.blah”, I believe it is not possible. There can be some workarounds to this though like using Bindable Functions etc.
ok i tried doing it but it did not work, and nothing happned can you help me?
local rp = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players")
plr.PlayerAdded:Connect(function()
local play = plr.PlayerAdded:Wait()
local axes = play:WaitForChild("axes")
print(axes.Normalaxe.Value)
if axes.Normalaxe.Value == false then
print("100")
play.PlayerGui.Side.ShopFrame.Background.ScrollingFrame.Axe.Buy.BackgroundColor3 = Color3.fromRGB(0, 221, 255)
play.PlayerGui.Side.ShopFrame.Background.ScrollingFrame.Axe.Buy.UIStroke.Color = Color3.fromRGB(0, 169, 221)
else
return
end
end)
okay when you are firing the PlayerAdded event, it passes a player as an argument.
Players.PlayerAdded:Connect(function(player: Player)
local axes = player:FindFirstChild("axes") -- I'm assuming this is some folder in player
if not axes then return end
local normalAxe = axes:FindFirstChild("Normalaxe")
if not normalAxe then return end
if not normalAxe.Value then
-- do something
end)
It should be best practice to always check if an instance exists so that you do not get an error
Like this, because if so then it does not work.
local rp = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players")
plr.PlayerAdded:Connect(function(player: Player)
local play = plr.PlayerAdded:Wait()
local axes = player:FindFirstChild("axes") -- I'm assuming this is some folder in player
if not axes then return end
local normalAxe = axes:FindFirstChild("Normalaxe")
if not normalAxe then return end
if not normalAxe.Value then
print(axes.Normalaxe.Value)
if axes.Normalaxe.Value == false then
print("100")
play.PlayerGui.Side.ShopFrame.Background.ScrollingFrame.Axe.Buy.BackgroundColor3 = Color3.fromRGB(0, 221, 255)
play.PlayerGui.Side.ShopFrame.Background.ScrollingFrame.Axe.Buy.UIStroke.Color = Color3.fromRGB(0, 169, 221)
else
return
end
end
end)
OHH it might be that you are trying to interact with the player GUI on the server side… if that is the case then you might wanna use remote events or (remote function if you want to return some value) and do GUI stuff on client side
Also, it does not print anything so idk about that either.
local re -- your remote event
Players.PlayerAdded:Connect(function(player: Player)
local axes = player:FindFirstChild("axes") -- I'm assuming this is some folder in player
if not axes then return end
local normalAxe = axes:FindFirstChild("Normalaxe")
if not normalAxe then return end
if not normalAxe.Value then
re:FireClient(player, ...) -- replace ... with values you might want to use on client side
end)
Where would I put ther other script to yk reseive the remote event
Somewhere a client can see, ie StarterPlayerScripts even the StarterGui is a valid option.
local re -- your remote event
local player = game.Players.LocalPlayer
re.OnClientEvent:Connect(function()
-- do GUI stuff
end)
thanks, but when I change the text it just does not do anything, here is the code,
script.Parent.Side.ShopFrame.Backgroud.ScrollingFrame.Axe.Buy.Text = "EQUIP"
Do not use script.Parent when you want to change any players GUI rather use the player instance (in this case the variable player)
So I would do:
local re -- your remote event
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
re.OnClientEvent:Connect(function()
PlayerGui. ... .Axe.Buy.Text = "Something" -- replace ... so that you reach the instance you want to change
end)
thanks for the help…
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.