Why Does it Print Everything?

Hello, so basically I have a server script where it listens to a RemoteEvent when an item is bought, and when it picks it up it gets the item_name and I want to figure out whether it is a horn, trail, or a vine.

The problem with this script is that it prints out all of the items available depending on its class (horns, vines, trail).

For example, if a player buys the Purple Horns, it will print out

Earthraphobic2 bought the Yellow Horns.
Earthraphobic2 bought the Purple Horns.
Earthraphobic2 bought the Red Horns.
Earthraphobic2 bought the Black Horns.

Here is the script idk what went wrong with it:

game.ReplicatedStorage.BuyItem.OnServerEvent:Connect(function(plr, item_name)
	local item = game.ServerStorage.Cosmetics[item_name]:Clone()

	if not item then
		return
	end

	if string.find(item_name, "Horns") then
		print(plr.Name.. " bought the " ..item_name)
	elseif string.find(item_name, "Trail") then
		print(plr.Name.. " bought the " ..item_name)
	elseif string.find(item_name, "Vines") then
		print(plr.Name.. " bought the " ..item_name)
	end
end)

What is point of the string.find?
Your printing out the same message in each of them

I want to detect which one it is because if it is horns, I want it to go on the head, however I also want the vines to go on the arms.

That’s why I am using string.find

How about you have a table that has all the items and what part of the body it corresponds too, then loop through that table and do what you need to do

Also if the cosmetics are accessories, you shouldnt have to tell where they have to go, the accessory will already be in the right position assuming you set it’s attachments positions correctly, once it’s put into the character it will position on its own

1 Like

Not a pro, but isn’t it just going through all the items in the Cosmetics folder, then naming them instead of finding the one just purchased?

1 Like

That is a good idea. Would it look something like this?

You’re right. I just re-read it and it does seem to be doing that.

I’m still confused as to why you have to tell the script where to put the cosmetic, if your using some other sort of accessory system then I get that but, if your not already using accessories you just put the accessory inside of the player’s character and it positions it where it needs to be

I’m positioning it inside the script because the horns are models and I don’t really know how to position it without using the script because won’t it automatically position it once the player joins?

Dude maybe try this out, it turns a model into an accessory im not sure if it still works but I just searched it up

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.