local Player = game:GetService(“Players”).LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumR = Character:WaitForChild(“HumanoidRootPart”)
local UIS = game:GetService(“UserInputService”)
local Events = game.ReplicatedStorage:WaitForChild(“Events”)
local RemoteFunction = Events:WaitForChild(“ListOwnDoors”)
local RemoteFunction = Events:WaitForChild(“BuyDoor”)
local OwnDoors = RemoteFunction:InvokeServer()
for i,v in pairs(OwnDoors) do
v:Destroy()
end
local Target
script.Parent.Buy.Buy.MouseButton1Click:Connect(function()
local Result = RemoteFunction:InvokeServer(Target)
if Result == true then
Target:Destroy()
Target = nil
script.Parent.Buy.Visible = false
else
script.Error:Play()
end
end)
function Buy()
if Target ~= nil then
local Magnitude = (HumR.Position-Target.Center.Position).Magnitude
if Magnitude <= Target.Range.Value then
script.Click:Play()
script.Parent.Buy.Visible = true
script.Parent.Buy.TextLabel.Text = Target.SurfaceGui.TextLabel.Text
end
end
end
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
if UIS:GetFocusedTextBox() == nil then
Buy()
end
end
end)
game:GetService(“RunService”).RenderStepped:Connect(function()
script.Parent.Frame.Visible = false
for i,v in pairs(workspace.Doors:GetChildren()) do
local Magnitude = (HumR.Position-v.Center.Position).Magnitude
if Magnitude <= v.Range.Value then
local WSP,Visible = workspace.CurrentCamera:WorldToScreenPoint(v.Center.Position)
if Visible then
script.Parent.Frame.Position = UDim2.new(0,WSP.X,0,WSP.Y)
script.Parent.Frame.Visible = true
Target = v
end
end
end
end)
local DataStore = game:GetService(“DataStoreService”)
local CoinsData = DataStore:GetDataStore(“CoinsData”)
local OwnDoorsData = DataStore:GetDataStore(“DoorData”)
local Events = game.ReplicatedStorage:WaitForChild(“Events”)
local RemoteFunction = Events:WaitForChild(“ListOwnDoors”)
local RemoteFunction = Events:WaitForChild(“BuyDoor”)
game.Players.PlayerAdded:Connect(function(Player)
local LS = Instance.new(“Folder”,Player)
LS.Name = “leaderstats”
local Coins = Instance.new("IntValue",LS)
Coins.Name = "Coins"
Coins.Value = CoinsData:GetAsync(Player.UserId) or 10000
local OwnDoors = Instance.new("StringValue",Player)
OwnDoors.Name = "OwnDoors"
OwnDoors.Value = OwnDoorsData:GetAsync(Player.UserId) or ""
end)
function Save(Player)
local LS = Player:WaitForChild(“leaderstats”)
local Coins = LS:WaitForChild(“Coins”)
local OwnDoors = Player:WaitForChild(“OwnDoors”)
CoinsData:SetAsync(Player.UserId,Coins.Value)
OwnDoorsData:SetAsync(Player.UserId,OwnDoors.Value)
end
game:BindToClose(function()
for i,v in pairs(game.Players:GetPlayers()) do
Save(v)
end
end)
RemoteFunction.OnServerInvoke = function(Player)
local OwnDoors = Player:WaitForChild(“OwnDoors”)
local Table = {}
for i,v in pairs(workspace.Doors:GetChildren()) do
if string.find(OwnDoors.Value,‘"’…v.Name…‘"’) then
table.insert(Table,v)
end
end
return Table
end
RemoteFunction.OnServerInvoke = function(Player,Target)
local LS = Player:WaitForChild(“leaderstats”)
local Coins = LS:WaitForChild(“Coins”)
local OwnDoors = Player:WaitForChild(“OwnDoors”)
local Price = Target.Price
if Coins.Value >= Price.Value then
Coins.Value = Coins.Value - Price.Value
OwnDoors.Value = OwnDoors.Value … ‘"’…Target.Name…‘",’
return true
else
return false
end
end
@MrLukeys It would be really helpful if your posts in #help-and-feedback:scripting-support gave some context to the issue. People here are more than happy to help if you give us details about what is wrong and maybe tell us what the output says when you run the code. Most people won’t reply to general requests like “Fix this code” or “What’s wrong with this?”
I read through the code and did see that you’re declaring the same local variable RemoteFunction to be two different events children of Events. This means that the second declaration of the variable RemoteFunction will be its value at run-time for your function calls.
You should have two variables:
local RemoteFunctionList = Events:WaitForChild("ListOwnDoors")
local RemoteFunctionBuy = Events:WaitForChild("BuyDoor")
As far as I can tell you are creating a string value inside of the player called OwnDoors and you’re using a combination of RemoteFunctions and DataStores to save values / create a client-server communication. I’m not really able to determine exactly the error with respect to the SurfaceGui you are talking about. I feel like the Target variable may have something to do with this since you reassign it in your client-side RenderStepped connected function, but then you pass it to the server too and juggle it quite a lot.
I’m sorry I couldn’t help more the issue isn’t too clear