Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

can't change string value?

Im trying to make a house buying system and to do that I put a string value named "Owner" inside of the house that I want to buy, why can't i change it to the players name?

server script:

local click = script.Parent
local house = script.Parent.Parent.Parent.Owner.Value
local rep = game:GetService("ReplicatedStorage")
local event = rep.Remotes:FindFirstChild("HouseBuyClient")
local event2 = rep.Remotes:FindFirstChild("HouseBuyServer")
print(house)
click.MouseClick:Connect(function(player)
	player.PlayerGui.HouseGui.buy.Visible = true
end)

event2.OnServerEvent:Connect(function(player, house)
	event:FireClient(player, house)
end)



localscript:

local rep = game:GetService("ReplicatedStorage")
local event = rep.Remotes:FindFirstChild("HouseBuyClient")
local event2 = rep.Remotes:FindFirstChild("HouseBuyServer")
local plr = game:GetService("Players").LocalPlayer

local button = script.Parent
local gui = button.Parent.Parent

event.OnClientEvent:Connect(function(player, house)
	house = tostring(plr.Name)
	
end)

button.MouseButton1Click:Connect(function()
	event2:FireServer(house)
	gui.Visible = false

end)

3 answers

I don't quite get why you would change the owner locally but okay.

But I think the problem is how you made the variables. Instead of local house = script.Parent.Parent.Parent.Owner.Value It should be just local house = script.Parent.Parent.Parent.Owner and then house = tostring(plr.Name) is changed to house.Value = tostring(plr.Name)

Server

local click = script.Parent
local house = script.Parent.Parent.Parent.Owner
local rep = game:GetService("ReplicatedStorage")
local event = rep.Remotes:FindFirstChild("HouseBuyClient")
local event2 = rep.Remotes:FindFirstChild("HouseBuyServer")
print(house)
click.MouseClick:Connect(function(player)
    player.PlayerGui.HouseGui.buy.Visible = true
end)

event2.OnServerEvent:Connect(function(player, house)
    event:FireClient(player, house)
end)

Local

local rep = game:GetService("ReplicatedStorage")
local event = rep.Remotes:FindFirstChild("HouseBuyClient")
local event2 = rep.Remotes:FindFirstChild("HouseBuyServer")
local plr = game:GetService("Players").LocalPlayer

local button = script.Parent
local gui = button.Parent.Parent

event.OnClientEvent:Connect(function(player, house)
    house.Value = tostring(plr.Name)

end)

button.MouseButton1Click:Connect(function()
    event2:FireServer(house)
    gui.Visible = false

end)

It's because when you "send" the script.Parent.Parent.Parent.Owner.Value It's sending the VALUE (string) of the "owner" not the OBJECT itself. By changing that, your just changing a value of a nothing.

Please try if it works.

Sorry for the bad explanation. You don't really need the OnClientEvent if you want the owner.Value to change for all players. For this, i make it changes the owner.Value in server for everyone. Server

local click = script.Parent
local houseValue = script.Parent.Parent.Parent.Owner
local rep = game:GetService("ReplicatedStorage")
local event = rep.Remotes:FindFirstChild("HouseBuyClient")
local event2 = rep.Remotes:FindFirstChild("HouseBuyServer")
print(houseValue.Value)
click.MouseClick:Connect(function(player)
	player.PlayerGui.HouseGui.buy.Visible = true
end)

event2.OnServerEvent:Connect(function(player, house)
	houseValue.Value = player.Name -- optional line
	event:FireClient(player, houseValue)
end)

If you keeping the event.OnClientEvent:Connect(function(player, house) then

Local

event.OnClientEvent:Connect(function(house) -- you don't need the player argument

maybe do

event.OnClientEvent:Connect(function(player, house)
house.Value = (plr.Name)

This discussion is preserved as it was. New answers, comments, and votes are closed.