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

Help with functions?!

Asked by 9 years ago

What i want the function to do is so when you touch the part it will make you bounce then it will do some fireworks? Here is the script.

local part = Instance.new("CFrameValue",Part2)--I added the 2 so it wouldn't do it for all the parts
CFrameVaule.Value = 2
function onTouch()
Player.CFrame = Player.CFrame.new(8,9,1)
wait(0.9)
local Workspace. = Instance.new("Part",Workspace)
local Workspace. = Instance.new("Part",Workspace)
local Workspace. = Instance.new("Part",Workspace)
local Workspace. = Instance.new("Part",Workspace)
local Workspace. = Instance.new("Part",Workspace)
local Workspace. = Instance.new("Part",Workspace)
local Workspace. = Instance.new("Part",Workspace)
Instances local Instances.Instance.new("Sound",Workspace)
Sound.SoundID = 12452 --I'll change this later
Sound:Play()
Instances local Instances.Instance.new("Explosion")
Explosion.Disabled = false
wait(0.1)--I wan't the explosion to start almost immediately
Explosion.Disabled = true
end
Part.Touched:connect(onTouched)
onTouched()

Help!

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

There are many problems with this. Because of that I might not be able to address everything but hopefully this will be a good start.


1) CFrame Value

The CFrameValue you create on the first line is unused. In addition, Part2 is not defined, so this essentially just deletes the new object by parenting it to nil.

CFrameValues Values are CFrames -- not numbers. Line 2 would be a "bad cast" since you are trying to give it a value of 2 for no reason.

As far as I can see, there isn't a point to including it, so just remove it and references to it.

2) onTouch() and Player

You do not define Player anywhere in the script. It can't just "know" what you're talking about, because Lua doesn't care about English. Player might as be asofdijog, which is unreadable to you but is exactly the same to the computer.

So you need to be explicit. The Player is the person who just touched it; to get what just touched it you use the first parameter to your onTouch function which many people usually call hit but I'll call touchingPart:

function onTouch(touchingPart)
    local Player = touchingPart.Parent;

If touchingPart was an arm or a head or a leg, then Player is now the model (the Character) that touched it. However, other things are allowed to touch this too that aren't players, so we need to check. Specifically, we'll check that Player is not nil, and that Player has a "Torso" object:

function onTouch(touchingPart)
    local Player = touchingPart.Parent;
    if Player and Player:FindFirstChild("Torso") then
        -- Remainder of onTouch function
    end
end

(We use FindFirstChild as a "Has Child" method here)

3) CFraming Characters

We said that Player should be the Character of a player, which is a Model and if you look, you'll see Models do not have CFrame properties; only Parts do. So we'll instead move the Player's Torso instead:

Player.Torso.CFrame = 

We want to "bounce" the player, which it looks like you wanted to do by teleporting them up a bit. We just add the position, there is no Player.CFrame.new to talk about (This is like asking, "What is five blocks from here.new(three blocks from here)?" The question you just want to ask is: "New distance(three blocks)"):

Player.Torso.CFrame = Player.Torso.CFrame + Vector3.new(8, 9, 1);

(We might also try setting the Velocity of the Torso to Vector3.new(8, 9, 1))


4) Parts

Don't make up syntax, that isn't remotely what Lua looks like.

To make a Part in the Workspace, we just need:

Instance.new("Part", Workspace);

We probably want to position those parts, though. I'm assuming we want to put them at Part.Position, the position of the Part that is being touched.

local p = Instance.new("Part",Workspace);
p.Position = Part.Position;

We can just copy and paste this line several times to make more parts; it would be better to do a for loop incase we change the number we want or make each part more complicated:

for i = 1, 10 do
    local p = Instance.new("Part",Workspace);
    p.Position = Part.Position;
end

5) Explosion

Explosions do not have a Disabled property.

Don't make up properties. The full reference is available. Don't make stuff up.

Explosions can't be disabled. They happen as soon as they appear in the workspace. Just move the wait(0.1) before creating the explosion.

6) Connection and Firing

The connection calls the function onTouched but the function is defined as onTouch; pick one and use it everywhere.

You use Part to connect to, and I reference it elsewhere because of this; however, you never defined Part. Most like it's something along the lines of script.Parent or so, but I can't really tell you that.

The final line, calling onTouch() yourself, is unnecessary unless you want to use it for debugging purposes. Since we now have it conditionally working on characters only, though, this will no longer accomplish anything and should be removed.

0
So can you give me the full script now that i understand the errors? iluvmaths1123 198 — 9y
0
You came here with a critically flawed script. If you can't put this together you really need to go over learning Lua again; you should use this oppurtunity to figure out how to put it all together since I gave you pretty much exactly what you need for each of the pieces that were wrong BlueTaslem 18071 — 9y
Ad

Answer this question