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 » Scripters
Home Search
 

Re: Could anyone fix this script or explain whats wrong in it?

Previous Thread :: Next Thread 
checkthefunkyguyHUNK is not online. checkthefunkyguyHUNK
Joined: 18 Mar 2013
Total Posts: 2638
30 Nov 2015 04:09 PM

This is a local script, and the purpose of this was to make a brick that will turn you into a zombie once you touch it.

face = game.Players.LocalPlayer.Character.Head.face
zombie = script.Parent.Parent.BootifulMoosic
humanoid = game.Players.LocalPlayer.Character.Humanoid
torso = game.Players.LocalPlayer.Character.Torso

function onTouched()
local Lelelel = Instance.new("Decal")
Lelelel.Texture = ("http://www.roblox.com/asset/?id=133667125")
wait(.20)
face:Destroy()
wait(.1)
Lelelel.Parent = game.Players.LocalPlayer.Character.Head
wait(.5)
zombie:Play()

if humanoid.Health == 0 then return end

end
Report Abuse
checkthefunkyguyHUNK is not online. checkthefunkyguyHUNK
Joined: 18 Mar 2013
Total Posts: 2638
30 Nov 2015 04:14 PM
Anyone?
Report Abuse
checkthefunkyguyHUNK is not online. checkthefunkyguyHUNK
Joined: 18 Mar 2013
Total Posts: 2638
30 Nov 2015 04:23 PM
COULD I JUST GET SOME HELP?!?
Report Abuse
T00NAMI is not online. T00NAMI
Joined: 10 Mar 2013
Total Posts: 211
30 Nov 2015 04:44 PM
Since this is done in a local script, you need to wait for the client to load the stuff from the server. Adding a bunch of wait's will work but only if the lag is minimal.
It is safer to just use WaitForChild because then the script is forced to stop until the child is found. Since the function can be called repeatedly, within the function you need to make it check if the object(s) still exist.

Here is an example that shows what I am talking about. Hopefully this helps!

local Player = game.Players.LocalPlayer
repeat wait() until Player ~= nil
local Character = Player.Character
repeat wait() until Character ~= nil
local Music = script.Parent.Parent:WaitForChild("BootifulMoosic")

function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health == 0 then return end
local Head = Character:FindFirstChild("Head")
if Head and Head:FindFirstChild("Face") then
Head.Face:Destroy()
local Decal = Instance.new("Decal")
Decal.Texture = "http://www.roblox.com/asset/?id=133667125"
Decal.Parent = Head
wait(0.5)
if Music then Music:Play() end
end
end
end
Report Abuse
checkthefunkyguyHUNK is not online. checkthefunkyguyHUNK
Joined: 18 Mar 2013
Total Posts: 2638
30 Nov 2015 05:10 PM
That didn't work...
Report Abuse
T00NAMI is not online. T00NAMI
Joined: 10 Mar 2013
Total Posts: 211
30 Nov 2015 05:33 PM
Oops I am sorry. I don't know why I have written that the way I did.
Must have been all the scripting I have done today. Anyways...

Try this version instead:

-- Make sure the script is a normal script inside the part, not a localscript.
-- Make sure to add the link to the musicId inside the script.


local Brick = script.Parent -- put this script inside the brick.
local MusicID = "" -- put music link here.

function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health == 0 then return end
local Head = hit.Parent:FindFirstChild("Head")
if Head and Head:FindFirstChild("Face") then
Head.Face:Destroy()
local Decal = Instance.new("Decal")
Decal.Texture = "http://www.roblox.com/asset/?id=133667125"
Decal.Parent = Head
wait(0.5)
local Music = Instance.new("Sound",Brick)
Music.Name = "ZombieSound"
Music.soundId = MusicID
Music.Volume = 1 Music.Pitch = 1
Music.Looped = false
Music:Play()
end
end
end

Brick.Touched:connect(onTouched)
Report Abuse
NormaINorm is not online. NormaINorm
Joined: 11 Dec 2012
Total Posts: 315
30 Nov 2015 05:34 PM
The player's character hasn't loaded when the script begins.

repeat wait() until game.Players.LocalPlayer.Character
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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