I was debugging my script with a print function that will print the value of a certain StringValue, which will change randomly. But I’m not really sure how, so I will need some help on this, please provide some help with the current script I’m using.
local function StandPunched(player)
local StandNamea = player:WaitForChild("StandValue") ---Getting the StringValue from the Player
StandNamea.Value.Changed:Connect() ---A really bad attempt at getting the latest value
local StandName = StandNamea.Value ---StringValue's Value
print(StandName) ---Printing Function
end
game.ReplicatedStorage.StandPunch.OnServerEvent:Connect(StandPunched)
I’ve tried the Dev Hub, but I didn’t find anything useful about this in it.
I tried to use Connect(Function() but It didn’t work out as much as I thought it would.
local function StandPunched(player)
local StandNamea = player:WaitForChild("StandValue")
StandNamea.Changed:Connect(function(Value)
print(Value)
end)
end
game.ReplicatedStorage.StandPunch.OnServerEvent:Connect(StandPunched)
I’ve write it like this, but it’s still not printing the new value. StandNamea is a StringValue, by the way.
Any mistakes I’ve made?
You’re making a something wrong. local StandNamea = player:WaitForChild("StandValue")
is going to be local StandNamea = player:WaitForChild("StandValue").Value
You’re accessing the string property not the value of it. @R3tr0_Alit0’
Add Value to all the properties you want to have the value of.
Show me the output aswell.
It’s giving me an error about "Attempting to index nil with “Connect” on StandNamea.Changed:Connect(function(Value)
after using the method you told me.
local function StandPunched(player)
local StandNamea = player:WaitForChild("StandValue").Value
StandNamea.Changed:Connect(function(Value)
if Value == "Value" then
print(StandNamea.Value)
end
end)
end
game.ReplicatedStorage.StandPunch.OnServerEvent:Connect(StandPunched)
You should only connect it once then if its been connected. I’m on my phone so this is hard to type lol.
local playerConnections = {}
local function StandPunched(player)
if not playerConnections[player] then
local StandNamea = player:WaitForChild("StandValue") ---Getting the StringValue from the Player
playerConnections[player] = {}
playerConnections[player].stringConnection = StandNamea.Changed:Connect(function(value)
end) ---A really bad attempt at getting the latest value
local StandName = StandNamea.Value ---StringValue's Value
print(StandName) ---Printing Function
end
game.ReplicatedStorage.StandPunched.OnServerEvent:Connect(StandPunched)
Hope you kinda get it. Cant really type it all out I’m at work atm.
Should I add the changed StringValue to the parameter in line of script that fires the event?
Like,
local StandNamea = script.Parent.Parent:WaitForChild("StandValue") ---The script is in the player's backpack and the Value is in player itself.
StandNamea.Changed:Connect(function(Value)
game.ReplicatedStorage.StandPunch:FireServer(Value)
I’m not very well with event callings and stuff like that, so correct me if I did something wrong up there.
game.ReplicatedStorage.StandPunch.OnServerEvent:Connect(function(plr)
if plr:WaitForChild("StandValue").Changed then
print(plr:WaitForChild("StandValue").Value)
end)
end)
I don’t think it will work, but worth a try send me the output message.