generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Detect a player's name

Previous Thread :: Next Thread 
iTopHatter is not online. iTopHatter
Joined: 24 Feb 2012
Total Posts: 2968
10 Jun 2012 08:26 AM
I'm trying to make crazyman's plane seat more advanced. I'm currently editing the Crash script so that a Hint is broadcasted upon a player crashing.

What I am trying to hopefully do is say "Oh no! (player) has crashed!"

This is what I have so far:

-- This script handles crash detection

while (not script.Parent.Cloned.Value) do wait() end
wait(5)

if (not script.Parent.EDIT_THESE.CanCrash.Value) then script:remove() return end
local maxImpact = script.Parent.EDIT_THESE.CanCrash.Force.Value

local crashT,explode = 0,false

local crashwarn Instance.new("Hint", game.Workspace) -- make a new hint when crashed
crashwarn.Name = "crashwarn" -- name
crashwarn.Text = "A plane has crashed! Oh no!" -- text

function goBoom() -- lol
explode = true
script.Parent.Dead.Stop.Value = true
local x = Instance.new("Explosion")
x.BlastPressure = 5e5
x.BlastRadius = script.Parent:GetModelSize().magnitude
x.Position = script.Parent.MainParts.Main.Position
script.Parent.MainParts.Main.Gyro:remove()
x.Parent = game.Workspace
end

function getParts(parent)
for _,v in pairs(parent:GetChildren()) do
if ((v:IsA("BasePart")) and (not v:IsDescendantOf(script.Parent.MainParts.LandingGear))) then
v.Touched:connect(function(obj)
if (not obj.Parent) then return end
if ((not obj.CanCollide) or (not v.CanCollide)) then return end
if (obj:IsDescendantOf(script.Parent)) then return end
if (game.Players:GetPlayerFromCharacter(obj.Parent)) then return end
if (
v.Velocity.x >= maxImpact
or
v.Velocity.x <= -(maxImpact)
or
v.Velocity.y >= maxImpact
or
v.Velocity.y <= -(maxImpact)
or
v.Velocity.z >= maxImpact
or
v.Velocity.z <= -(maxImpact)
)
then
if (not script.Parent.Dead.Value) then
crashT = time()
script.Parent.Dead.Value = true
game:GetService("Debris"):AddItem(script.Parent,8)
delay(6,function()
pcall(function() script.Parent.MainParts.MainSeat.SeatWeld:remove() end)
if (not explode) then
goBoom()
end
end)
end
end
if ((script.Parent.Dead.Value) and ((time()-crashT) > 0.5) and (not explode)) then
goBoom()
end
end)
end
getParts(v)
end
end

getParts(script.Parent)

script.Parent.AutoCrash.Changed:connect(function()
if (not script.Parent.AutoCrash.Value) then return end
if ((not explode) and (not script.Parent.Dead.Value)) then
crashT = time()
script.Parent.Dead.Value = true
game:GetService("Debris"):AddItem(script.Parent,8)
goBoom()
end
end)

~𝓲𝓣𝓸𝓹𝓗𝓪𝓽𝓽𝓮𝓻
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
10 Jun 2012 08:41 AM
Pro tip. Replace:

    if (
        v.Velocity.x ​>= maxImpact
    or
        v.Velocity.x <= -(maxImpact)
    or
        v.Velocity.y ​>= maxImpact
    or
        v.Velocity.y <= -(maxImpact)
    or
        v.Velocity.z ​>= maxImpact
    or
        v.Velocity.z <= -(maxImpact)
    )

With

   if v.Velocity.magnitude ​>= maxImpact
Report Abuse
iTopHatter is not online. iTopHatter
Joined: 24 Feb 2012
Total Posts: 2968
10 Jun 2012 08:48 AM
I fixed the hint instancing, there's a simple problem, the hint won't go away.

-- This script handles crash detection

while (not script.Parent.Cloned.Value) do wait() end
wait(5)

if (not script.Parent.EDIT_THESE.CanCrash.Value) then script:remove() return end
local maxImpact = script.Parent.EDIT_THESE.CanCrash.Force.Value

local crashT,explode = 0,false



function goBoom() -- lol
explode = true
script.Parent.Dead.Stop.Value = true
local x = Instance.new("Explosion")
x.BlastPressure = 5e5
x.BlastRadius = script.Parent:GetModelSize().magnitude
x.Position = script.Parent.MainParts.Main.Position
script.Parent.MainParts.Main.Gyro:remove()
x.Parent = game.Workspace
local Message = Instance.new("Hint", game.Workspace)
Message.Name = "Hint"
Message.Text = "A plane has crashed! Oh no!"
wait(15)
Message:remove() -- not working
end

function getParts(parent)
for _,v in pairs(parent:GetChildren()) do
if ((v:IsA("BasePart")) and (not v:IsDescendantOf(script.Parent.MainParts.LandingGear))) then
v.Touched:connect(function(obj)
if (not obj.Parent) then return end
if ((not obj.CanCollide) or (not v.CanCollide)) then return end
if (obj:IsDescendantOf(script.Parent)) then return end
if (game.Players:GetPlayerFromCharacter(obj.Parent)) then return end
if v.Velocity.magnitude ?>= maxImpact
then
if (not script.Parent.Dead.Value) then
crashT = time()
script.Parent.Dead.Value = true
game:GetService("Debris"):AddItem(script.Parent,8)
delay(6,function()
pcall(function() script.Parent.MainParts.MainSeat.SeatWeld:remove() end)
if (not explode) then
goBoom()
end
end)
end
end
if ((script.Parent.Dead.Value) and ((time()-crashT) > 0.5) and (not explode)) then
goBoom()
end
end)
end
getParts(v)
end
end

getParts(script.Parent)

script.Parent.AutoCrash.Changed:connect(function()
if (not script.Parent.AutoCrash.Value) then return end
if ((not explode) and (not script.Parent.Dead.Value)) then
crashT = time()
script.Parent.Dead.Value = true
game:GetService("Debris"):AddItem(script.Parent,8)
goBoom()
end
end)

~𝓲𝓣𝓸𝓹𝓗𝓪𝓽𝓽𝓮𝓻
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
10 Jun 2012 08:50 AM
Use `:Destroy()` instead
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
10 Jun 2012 08:56 AM
Also, that code is trying to be Lisp. It has way too many `(`s and `)`s. Here it is without them:

    while not script.Parent.Cloned.Value do wait() end
    wait(5)
    
    if not script.Parent.EDIT_THESE.CanCrash.Value then script:remove() return end
    local maxImpact = script.Parent.EDIT_THESE.CanCrash.Force.Value
    
    local crashT, explode = 0, false
    
    
    function goBoom() -- lol
        explode = true
        script.Parent.Dead.Stop.Value = true
        
        local x = Instance.new("Explosion")
        x.BlastPressure = 5e5
        x.BlastRadius = script.Parent:GetModelSize().magnitude
        x.Position = script.Parent.MainParts.Main.Position
        script.Parent.MainParts.Main.Gyro:remove()
        x.Parent = game.Workspace
    
        local Message = Instance.new("Hint", game.Workspace)
        Message.Name = "Hint"
        Message.Text = "A plane has crashed! Oh no!"
        wait(15)
        Message:Destroy() -- not working
    end
    
    function getParts(parent)
        for _,v in pairs(parent:GetChildren()) do
            if v:IsA("BasePart") and not v:IsDescendantOf(script.Parent.MainParts.LandingGear) then
                v.Touched:connect(function(obj)
                    if not obj.Parent then return end
                    if not obj.CanCollide or not v.CanCollide then return end
                    if obj:IsDescendantOf(script.Parent) then return end
                    if game.Players:GetPlayerFromCharacter(obj.Parent) then return end
                    if v.Velocity.magnitude ​>= maxImpact then
                        if not script.Parent.Dead.Value then
                            crashT = time()
                            script.Parent.Dead.Value = true
                            game:GetService("Debris"):AddItem(script.Parent,8)
                            delay(6, function()
                                pcall(function() script.Parent.MainParts.MainSeat.SeatWeld:remove() end)
                                if not explode then
                                    goBoom()
                                end
                            end)
                        end
                    end
                    if script.Parent.Dead.Value and time() - crashT ​> 0.5 and not explode then
                        goBoom()
                    end
                end)
            end
            getParts(v)
        end
    end
    
    getParts(script.Parent)
    
    script.Parent.AutoCrash.Changed:connect(function()
        if not script.Parent.AutoCrash.Value then return end
        if not explode and not script.Parent.Dead.Value then
            crashT = time()
            script.Parent.Dead.Value = true
            game:GetService("Debris"):AddItem(script.Parent,8)
            goBoom()
        end
    end)
Report Abuse
iTopHatter is not online. iTopHatter
Joined: 24 Feb 2012
Total Posts: 2968
10 Jun 2012 09:02 AM
Now it's not crashing, and if you force it to crash by resetting or dying, it doesn't show a hint...I'll try my best to fix it

~𝓲𝓣𝓸𝓹𝓗𝓪𝓽𝓽𝓮𝓻
Report Abuse
iTopHatter is not online. iTopHatter
Joined: 24 Feb 2012
Total Posts: 2968
10 Jun 2012 09:18 AM
Alright. I've decided that removing isn't going to work, so I want to make the hint say
"(player) is the most recent failed pilot. Tsk tsk tsk." However, how do I detect a player's name? I've tried using

x = script.Parent.Parent.Name -- script.Parent.Parent is actually the player

However, hints dont support this, so how do I get it to say the player's name?

~𝓲𝓣𝓸𝓹𝓗𝓪𝓽𝓽𝓮𝓻
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
10 Jun 2012 09:24 AM
>  hints dont support this

I have no idea what you mean. If you have the players name, you can definitely set a hint's message to it.
Report Abuse
iTopHatter is not online. iTopHatter
Joined: 24 Feb 2012
Total Posts: 2968
10 Jun 2012 09:30 AM
No, I want whoever crashed the plane's name. It could be anyone.

I mean if I get the player's name like

script.Parent.Parent.Name = x

if I put "x crashed the plane", it literally appears as "x crashed the plane" not "(player) crashed the plane"

~𝓲𝓣𝓸𝓹𝓗𝓪𝓽𝓽𝓮𝓻
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
10 Jun 2012 09:35 AM
Oh. You need the concatenation operator, `..`:

    hint.Text = script.Parent.Parent.Name .. " crashed the plane"

Or option two, `string.format`:

    hint.Text = ("%s crashed the plane"):format(script.Parent.Parent.Name)
Report Abuse
iTopHatter is not online. iTopHatter
Joined: 24 Feb 2012
Total Posts: 2968
10 Jun 2012 09:40 AM
Thanks! It works!

~𝓲𝓣𝓸𝓹𝓗𝓪𝓽𝓽𝓮𝓻
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image