1
votes

I'm very confused. I'm trying to make it so that if you hold E with Roblox's "ProximityPrompt", you will get a GUI on your screen with some text. Everything works except that the text won't work. I also am not writing a string on the client script. There is a variable for it on the server script that gets passed over. But I keep seeing this error in the output.

Players.ford200000.PlayerGui.BuyGui.Frame.TextInput.Text:2: attempt to concatenate nil with string - Client -

Here is what I'm doing in my script

local sp = script.Parent
sp.ProximityPrompt.Triggered:Connect(function(player)
    local name = sp.Name
    local ss = game.ServerStorage
    local item = ss.Hats:FindFirstChild(name)
    local price = item.Price
    game.ReplicatedStorage.ShopClickEvent:FireClient(player)
    game.ReplicatedStorage.ShopInfoEvent:FireClient(player)
end)

And in the local script that listens for ShopInfoEvent

game.ReplicatedStorage.ShopInfoEvent.OnClientEvent:Connect(function(player, price, item)
    script.Parent.Text = "Would you like to buy this ".. item.Name .." for ".. price.Value .."?"
end) 

Please help, that would be greatly appreciated.

2
Could you post your code?Kylaaa
local sp = script.Parent sp.ProximityPrompt.Triggered:Connect(function(player) local name = sp.Name local ss = game.ServerStorage local item = ss.Hats:FindFirstChild(name) local price = item.Price game.ReplicatedStorage.ShopClickEvent:FireClient(player) game.ReplicatedStorage.ShopInfoEvent:FireClient(player) end) Server scriptford200000
game.ReplicatedStorage.ShopInfoEvent.OnClientEvent:Connect(function(player, price, item) script.Parent.Text = "Would you like to buy this ".. item.Name .." for ".. price.Value .."?" end) Client scriptford200000
@ford200000 please not that posting code in comments is not a good as you cannot format it properly. Instead, edit your question.Piglet

2 Answers

2
votes

Your error is telling you that the object you are trying to add to a string is undefined. This could be item.Name or price.Value is undefined and causing this string construction to fail.

Looking at how you are defining item and price shows that both of these values are undefined in your LocalScript's callback. When you call a RemoteEvent's FireClient function, the first argument tells the engine who to send the event to, and all the other arguments get passed in as the arguments of the callback. Currently, you aren't passing in any arguments at all.

So to fix your problem, you need to pass in the right arguments from the Script:

game.ReplicatedStorage.ShopInfoEvent:FireClient(player, price, item)

and parse them properly in your LocalScript :

game.ReplicatedStorage.ShopInfoEvent.OnClientEvent:Connect(function(price, item)
    script.Parent.Text = "Would you like to buy this ".. item.Name .." for ".. tostring(price.Value) .."?"
end) 
2
votes

Players.ford200000.PlayerGui.BuyGui.Frame.TextInput.Text:2: attempt to concatenate nil with string - Client -

tells you everything you need to know.

You're trying to concatenate nil with string. That means you're using the string concatenation operator .. with a nil operand in line 2

So let's look into line 2

script.Parent.Text = "Would you like to buy this ".. item.Name .." for ".. tostring(price.Value) .."?"

"Would you like to buy this ", " for " and "?" are obviously strings. That leaves us with item.Name and tostring(price.Value).

If price.Value were nil, tostring would turn it into "nil". So this cannot be the cause of this particular error message.

That leaves us with item.Name. If item were nil we would see an error for indexing a nil value instead. So that tells us that whatever item is, it is not what we expected to be. A table with an element for key "Name".

At this moment you know that something is wrong with the parameters of your function. So you (hopefully again) refer to the manual and compare that with the way you use those event functions.