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

How do i make a player get killed by a chance?

Asked by 5 years ago

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

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

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
0
And you were checking in workspace for the localplayer blockmask 374 — 5y
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. Aniline_Purple 266 — 5y
0
Good job, though! Aniline_Purple 266 — 5y
0
Thank you alot, both of you! How do I choose that i have the answer tho? Proobitaz 0 — 5y
View all comments (4 more)
1
if you want a number between 0 and 1, just use math.random() without any parameters theking48989987 2147 — 5y
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. Isaque232 171 — 5y
0
@theking48989987 damn, didn't know that, thanks! Aniline_Purple 266 — 5y
0
Oh, right, I forgot they only return integers blockmask 374 — 5y
Ad

Answer this question