So im trying to get the player, if he clicks a button(Text button) a part spawns, i got no problem with that, but when i try to make it so when the play touches the part they take damage, it doesnt work. Here is the following code
01 | local btn = game.StarterGui.test 2. test |
02 | function SpawnShadowPart() |
03 | local Shadow = Instance.new( "Part" ) |
04 | Shadow.Parent = workspace |
05 | Shadow.Shape = "Cylinder" |
06 | Shadow.Name = "ShadowCurse" |
07 | Shadow.Position = Vector 3. new( 0 , 10 , 0 ) |
08 | Shadow.Orientation = Vector 3. new( 0 , 10 , 0 ) |
09 | Shadow.Color = Color 3. fromRGB( 170 , 0 , 170 ) |
10 | end |
11 |
12 |
13 |
14 | local shadow = game.workspace:FindFirstChild( "ShadowCurse" ) |
15 | script.Parent.MouseButton 1 Click:Connect( function () |
Your function isn't returning anything. If you wanna get the touching part, you'll need to return something. Which is an instance.
01 | local btn = game.Players.LocalPlayer:WaitForChild( "PlayerGui" ).test 2. test --Manipulate the PlayerGui, not StarterGui. Also you can use script.Parent if your local script is a descendant of ScreenGui. |
02 | function SpawnShadowPart() |
03 | local Shadow = Instance.new( "Part" ) |
04 | Shadow.Parent = workspace |
05 | Shadow.Shape = "Cylinder" |
06 | Shadow.Name = "ShadowCurse" |
07 | Shadow.Position = Vector 3. new( 0 , 10 , 0 ) |
08 | Shadow.Orientation = Vector 3. new( 0 , 10 , 0 ) |
09 | Shadow.Color = Color 3. fromRGB( 170 , 0 , 170 ) |
10 | return Shadow --We need the object. |
11 | end |
The reason why is because the function isn't returning anything, it's only returning nil, which WILL break your script. You need to return the object in order for it to work.