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

How do I allow a script to find out that a StringValue's value has changed?

Asked by 5 years ago
Edited 5 years ago

I have a LocalScript that fires a remote and changes the value of a StringValue. I have a script that finds that the remote was fired and finds the value. It goes through a list of items until the name matches the value, it then places it into the Workspace. In output I'm finding out that the script is not even recognizing that the StringValue's value has even changed at all. How do I fix this?

The LocalScript

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RewardedBelts = ReplicatedStorage:WaitForChild("Belts")
local InventoryGui = PlayerGui:WaitForChild("InventoryGui")
local Scroll = InventoryGui.Inventory.ScrollingFrame
local Equip = InventoryGui.Inventory.Equip
local Chosen = InventoryGui.Inventory:WaitForChild("Selected")
local Workspace = game:GetService("Workspace")
local BeltValue = Workspace:WaitForChild("BeltValue")
local Remote = ReplicatedStorage:FindFirstChild("Opened")

Equip.MouseButton1Click:Connect(function()
    local TheText = Chosen:WaitForChild("TextLabel")
    local TheBelts = RewardedBelts:GetDescendants()
    BeltValue.Value = TheText.Text
    Remote:FireServer()
    InventoryGui.Enabled = false
end)

The Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game.Workspace
local RewardedBelts = ReplicatedStorage:WaitForChild("Belts")
local BeltValue = Workspace:WaitForChild("BeltValue")

game.ReplicatedStorage.Opened.OnServerEvent:Connect(function(player)
    print("Connected")
    local TheBelts = RewardedBelts:GetDescendants()
    for i,v in pairs (TheBelts) do
        if v:IsA("UnionOperation")then
            print(v.Name.. " is usable")
            if BeltValue.Value == "Blank" then repeat wait() until BeltValue.Value ~= "Blank"
            print(BeltValue.Value.. " is the BeltValue")
            if v.Name == BeltValue.Value then
                print("Found" ..v)
                local R = v:Clone()
                R.Parent = game.workspace
                print("The Belt has been placed in the workspace.")
                end
            end
        end
    end
end)
0
Values have a Changed property. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

Your issue is that you are changing the belt value client side

Have a look at this code snippet here

lua Equip.MouseButton1Click:Connect(function() local TheText = Chosen:WaitForChild("TextLabel") local TheBelts = RewardedBelts:GetDescendants() BeltValue.Value = TheText.Text Remote:FireServer() InventoryGui.Enabled = false end)

It is being changed from the LocalScript.

You can pass the text of your TextLabel to the server, and have the server set the Value of BeltValue to whatever was received

Sort of like this:

lua remoteEvent.OnServerEvent:Connect(function(client, value) beltValue.Value = value; end);

With proper security checks of course

0
Thank you very much, I abandoned the use of the StringValue in the Workspace and instead I just sent the text by local BeltName = TheText.Text; FireServer(BeltName). songboy50 77 — 5y
Ad

Answer this question