Can You Do If print said a "Part Clone" and if the print does that it will clone the part

So, The problem is that if print said "“Part Clone” it will clone the part.

I tried and nothing is working

Scripts

script.Parent.ClickDetector.MouseClick:Connect(function()
	print("Part Clone")
end)

Script 2

if print == "Part Clone" then
	local part = Instance.new("Part")
	part.Position = game.Workspace.SpawnLocation.Position
end

It didn’t give me a output error, but it is not working.

3 Likes

Are both of these server scripts? Are you trying to make the client communicate with the server (or viceversa)? If the goal here is to clone a part on MouseClick then you don’t need any checks.

Its all the scripts not local i want to make like if print said “Part Clone” it will make a part.

You can’t do that, print is not a variable and it cannot “store” any values. It’s a base method of Luau.
What you’re looking for are BindableEvents:

-- SCRIPT 1
local bindable = Instance.new("BindableEvent");
bindable.Parent = game:GetService("ServerScriptService");
script.Parent.ClickDetector.MouseClick:Connect(function()
	bindable:Fire("Part Clone");
end)
-- SCRIPT 2
game:GetService("ServerScriptService"):WaitForChild("BindableEvent").Event:Connect(function(value)
	if value == "Part Clone" then
        local part = Instance.new("Part")
	    part.Position = game.Workspace.SpawnLocation.Position
        part.Parent = workspace;
    end;
end)

Did you parent the part to workspace?

It got infinite yield error and it is not working

Try with :WaitForChild("Event") instead of BindableEvent

like this ?

Instance.new:WaitForChild("Bindable")

No I mean the line I wrote to wait for the bindable:

game:GetService("ServerScriptService"):WaitForChild("Event").Event:Connect(function(value)

Change it to this (in your script 2).

2 Likes

yep it works thank you so much

1 Like

This is possible using a service. RunService I think? You could detect when an input is sent, and if the message is “Clone Part,” then it will make a part.

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