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

How do I make a randomized click giver?

I'm trying to make a randomized click giver, but I don't know what I'm doing wrong.

local Weapons = game.ReplicatedStorage.Weapons:GetChildren()

function onClick(plyr)

script.Parent.ClickDetector.MouseClick:connect(onClick)

local Weapon = Weapons[math.random(1,#Weapons)]:Clone()
Weapon.Parent = game.Players.LocalPlayer.Backpack

end

Thanks if you can help, I'm also a bit of a noob, so please go easy!

1 comment

0

Could you be a little more specific in your question? Also a little more of your code would help me see what is wrong.

1 answer

So there are a few problems with your script :

  • Line 5 should be outside the function, otherwise the function won’t connect to the event and the function will never run.

  • ClickDetectors (I think) can only work with server scripts and not local scripts. On line 8, use “plyr” instead of “game.Players.LocalPlayer”, as LocalPlayer only works in local scripts.

  • Use “:Connect” instead of “:connect”. They both still work but “:connect” is deprecated, so it’s recommended to use the other one.

That’s all the errors I see in this script so far. If there are any other problems happening still, just comment and I’ll get back to you soon.

1 comment

0

Didn't exactly work, but thanks for trying!

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