I want to use RemoteFunction to update the name of a StringValue inside of a player. I would do this using a server-sided script but the name being updated is inside of a LocalScript so the name will only be changed locally and I want the server to recognize the change too.
Inside the local script (segment):
equipButton.MouseButton1Click:Connect(function()
clickSound:Play()
if equipButton.Image == "rbxassetid://17316025753" then
if sword then
changeImage()
equippedSwordChangedEvent:FireServer(sword_to_give) -- RemoteEvent is fired
equipButton.Image = "rbxassetid://17316048949"
end
elseif equipButton.Image == "rbxassetid://17316048949" then
equipButton.Image = "rbxassetid://17316025753"
end
end)
Inside of the server side script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local equippedSwordChangedEvent = ReplicatedStorage:WaitForChild("EquippedSwordChangedEvent")
local function updateEquippedSword(player, equippedSwordName)
if equippedSwordName then
player:SetAttribute("EquippedSword", equippedSwordName)
else
player:SetAttribute("EquippedSword", nil)
end
end
equippedSwordChangedEvent.OnServerEvent:Connect(function(player, equippedSwordName) -- listens for event
updateEquippedSword(player, equippedSwordName)
end)
However, the StringValue name does not update when the event is fired. No outputs in error.
i am confused, you’re firing an event from the localscript, and binded a function on the server script?
these are not related. where… do you listen to the client event? where does the client invoke the server function?
Adjusted the script a bit, the localscript (a segment of it) is:
equipButton.MouseButton1Click:Connect(function()
clickSound:Play()
if equipButton.Image == "rbxassetid://17316025753" then
if sword then
changeImage()
equippedSwordChangedEvent:FireServer(sword_to_give) -- RemoteEvent is fired
equipButton.Image = "rbxassetid://17316048949"
end
elseif equipButton.Image == "rbxassetid://17316048949" then
equipButton.Image = "rbxassetid://17316025753"
end
end)
Server-Side Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local equippedSwordChangedEvent = ReplicatedStorage:WaitForChild("EquippedSwordChangedEvent")
local function updateEquippedSword(player, equippedSwordName)
if equippedSwordName then
player:SetAttribute("EquippedSword", equippedSwordName)
else
player:SetAttribute("EquippedSword", nil)
end
end
equippedSwordChangedEvent.OnServerEvent:Connect(function(player, equippedSwordName) -- listens for event
updateEquippedSword(player, equippedSwordName)
end)
The “EquippedSword” StringValue name still does not change after the event is fired.