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 player get killed by a chance?

I am VERY NEW to scripting and I am trying to make a script that kills the localplayer if the value is under .2 using math.random(1). i tried multiple times with no success. pls help thx

script.Parent.MouseButton1Click:connect(function()
	math.random(1)
	if math <0.2
	then
		game.Workspace.LocalPlayer:BreakJoints()

function Break(Player)
Player.Character:BreakJoints()
end
	end
end)

Thanks in advance!

1 answer

So you need to set that math.random(), in a variabe.

local number = math.random(1)

And now, under the mouseclick event, pace this in there, so the number is new everytime with the click

script.Parent.MouseButton1Down:Connect(function()
	local number = math.random(1)
end)

so now check for the number with an if statement, and kill the player

if (number < 0.2) then
	if game.Players.LocalPlayer.Character then
		game.Players.LocalPlayer.Character:BreakJoints()
	end
end

8 comments

0

And you were checking in workspace for the localplayer

0

Hi, math.random only returns integer values. Your answer is correct, though, but I suggest just doing math.random(100) then checking if the value is less than the percentage you'd like, in this case, 20.

0

Good job, though!

0

Thank you alot, both of you! How do I choose that i have the answer tho?

1

if you want a number between 0 and 1, just use math.random() without any parameters

0

You can now just check for the value as It'll be already random. " if number < 20 then " then you just do whatever you were going to do with it being random.

0

@theking48989987 damn, didn't know that, thanks!

0

Oh, right, I forgot they only return integers

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