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

I made a script and when I went to test it, it wouldn't work.Why?

I made a script that makes it where if you click on a GUI button it is supposed to clone a model from ServerStorage to Workspace but when I test the game, when I click on the button nothing happens and I see no errors. Could someone tell me why? This is the code I made.

local redMachineGun = game.ServerStorage.RedSoldiers.RedArcticSoldier

local clickDetector1 = game.StarterGui.ScreenGui.ScrollingFrame1.Machine.ClickDetector

local function clone1()
	redMachineGun:Clone().Parent = workspace
end

function onMouseClick1()
	clone1()
end

clickDetector1.MouseClick:connect(onMouseClick1)

1 answer

✓ Accepted answer

Hey Timber, you seem to have a lot of misunderstanding about the Roblox client-server model. I'll give you the straight steps for doing what you'd like but first, indexing the StarterGui is the wrong thing to do as the contents inside there get cloned into each player that joins, you'd want to index through game.Players.LocalPlayer.PlayerGui.

Next, you'd want to connect an event like you have here, except a gui button would be: buttonReference.MouseButton1Click:Connect(onMouseClick1)

You'd then want to fire a RemoteEvent and then receive the call in a server script in ServerScriptService, you'd then want to clone the model like you have with the clone1() function.

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