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

Why Does This Work In Studio And Not In A Regular Roblox Server?

I understand that my question is very broad but I did not know how else to put it. To give you some context, I watching a tutorial about DataStorage and how to make it work with a shop GUI. The video I was watching on YT (https://www.youtube.com/watch?v=I-juZw7pmuQ&t). In short, I created a saving currency DataStorage and a shop GUI. When a player has enough points for an item in the shop, it will clone the item into the player's backpack and into the starter gear. This was successful in Roblox Studio but not in the Roblox Server.

Local Script:

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			game:GetService("ReplicatedStorage").Events.RemoteEvent:FireServer(v.Name, v.ItemPrice)
		end)
	end
end

Script:

game:GetService("ReplicatedStorage").Events.RemoteEvent.OnServerEvent:Connect(function(player, item, price)
	print(price)	
	if player.Money.Value >= price.Value then
		local itemClone = game:GetService("ServerStorage")[item]:Clone()
		itemClone.Parent = player.Backpack
		
		local itemClone2 = game:GetService("ServerStorage")[item]:Clone()
		itemClone2.Parent = player.StarterGear
	end
end)

It returns an error saying "attempt to index local 'price' (a nil value)". Please look at the video I provided to try it out for yourself.

2 comments

0

Since this is not your script, we can't help you.

0

@incapaz How come? It's off a YouTube tutorial. I understand it. I know how it works. I just can't seem to figure out why it only works on studio and not on a regular server.

1 answer

✓ Accepted answer

ah, the classic problem of 'this works in studio but not a server'; i hate those i'm not sure what ItemPrice is, but, from what i can infer, it seems to be a number value.

you're giving the server either the ItemPrice object, and, servers cant really deal with client-side objects. i'm no expert, so, don't quote me, but, i think it would work better if instead of just trying to set it to the object, set it to the value, like this:

game:GetService("ReplicatedStorage").Events.RemoteEvent:FireServer(v.Name, v.ItemPrice.Value)

and replace "price.Value" with just price, since, it should be just a number.

hopefully i helped!

3 comments

0

I have not tried this out yet because I wanted to start over. I can try to do the solution you posted and see if it worked. I will keep you updated if everything went well or not.

0

alright, good luck! when studio throws these kinds of problems at me, it's often a trial and error type of process. hope it goes well!

0

You were right. Everything went super well. Thanks for the help!

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