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

How do I make a button that gives you a force field?

I want to make a button that when you click on it, it gives the clicker a force field. How do I do this? (I did not forget the ClickDetector)

Part = script.Parent  ---Part is the button



function giveForceField()
	game.Players.LocalPlayer = Instance.new('ForceField')
end



Part.ClickDetector.MouseClick:connect(giveForceField)

2 comments

0

Did you try? That doesn't look like trying. Learn the language and understand the concepts first.

0

You're right. I did not try my best, I shall keep on trying and read the wiki.

1 answer

✓ Accepted answer

I really do have the feeling you aren't trying and are not motivated to script. This became quite clear to me when you come here for help before trying anything yourself. Everything in this script could have easily been found with the help of the wiki

Please try.

http://wiki.roblox.com/index.php?title=API:Class/ClickDetector

ClickDetectors work like this:

1) Set it up

local clicker=script.Parent--This script should be in the clickdetector


function onMouseClick(plr)-- The parameter(Argument) is the player that clicked it.


end
clicker.MouseClick:connect(onMouseClick)

2) Create a character variable and create a new forcefield instance.

local character=plr.Character
Instance.new("ForceField", character)



3) What the final code should look like:


local clicker=script.Parent--This script should be in the clickdetector


function onMouseClick(plr)-- The parameter(Argument) is the player that clicked it.
	local character=plr.Character
	Instance.new("ForceField", character)
end
clicker.MouseClick:connect(onMouseClick)

This is stuff that was extremely easy for me to find with the help of the wiki. I suggest you use it as a ressource before posting here.

Cheers!

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