How can I fire this event multiple times in a session?

I have a textbox and a button. I want it so that when you click the button, whatever you typed into the textbox spawns on the map near you. So far I’ve been able to resolve tons of bugs in the last few hours, and I believe this could be my last thread for now.

I’ve been able to make the entire script work, and each of the requested models does spawn, however, just once.

-- button local script, fires the event
local RE = game.ReplicatedStorage.RemoteEvent
local button = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.ImageButton
local textBox = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.TextBox

button.MouseButton1Click:Connect(function()
	RE:FireServer(string.lower(textBox.Text))
end)
-- serverscriptservice server script, processes the event
...

RE.OnServerEvent:Connect(function(plr, textInput)
	if repstorage.Stuff:FindFirstChild(textInput) then
		local model = repstorage.Stuff:FindFirstChild(textInput)
		local modelclone = model:Clone()
		
		modelclone.Parent = workspace
		modelclone:SetPrimaryPartCFrame(humroot.CFrame)
		modelclone:TranslateBy(Vector3.new(5, 0, 5))
	else
		...
	end
end)

I’d like the models to be cloned each time I ask for them. Any ideas on how could I make that happen?

2 Likes

Just to clarify the problem is that it will only work for the first time and never again?

That’s right, each model only spawns once and retyping the same thing won’t work until you restart the game.

What’s the model name you want to search for?

So far I have these two things.
image

I’ve been able to spawn one chair and one couch simultaneously, but not two couches or two chairs.

Can you show the Stuff folder after you’ve inputted the model name(s)?

Any errors?
Try doing some print debugging, I would add some random print statements and see if anything out of the ordinary happens so that I can pinpoint the problem
like in between here

print something to see if it will run when you type the item for a second time.
you can also try printing the model after

Weird. Maybe it has something to do with the methods? (e.g. SetPrimaryPartCFrame)

I was able to find out Roblox was throwing an error about the SetPrimaryCPartFrame thing the whole time:

The script detects that a known string is used and clones the part, however gets stuck when the parameters are specified because this line is written incorrectly.

How do I fix it?

1 Like

Maybe each time you clone the item, you set a PrimaryPart for the model.

Or just set PrimaryPart manually through the model’s properties.

2 Likes

why not use PivotTo()?

ihaterobloxcharlimits

2 Likes
-- serverscriptservice server script, processes the event

RE.OnServerEvent:Connect(function(plr, textInput)
	if repstorage.Stuff:FindFirstChild(textInput) then
		local model = repstorage.Stuff:FindFirstChild(textInput)
		local modelclone = model:Clone()
		
		modelclone.Parent = workspace
		modelclone:PivotTo(humroot.CFrame)
		modelclone:TranslateBy(Vector3.new(5, 0, 5))
	else
		...
	end
end)
2 Likes

you don’t need a PrimaryPart for PivotTo().

Thank you! This will save me a lot of work. The basics of my game are now done and I don’t have to worry about making dozens of threads on the Devforum anymore. :slight_smile:

1 Like

It’s okay. I’m glad I could help!

1 Like

And I glad I could help on that one post :slight_smile:

1 Like

You were also right, you could just apply the PrimaryPart manually.

Yeah, but I didn’t think of Model:PivotTo(). I forgot that method even existed :rofl: