Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a randomized click giver?

Asked by 6 years ago

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!

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. User#21908 42 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

0
Didn't exactly work, but thanks for trying! CaptainAlien132 225 — 6y
Ad

Answer this question