Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How come my Water for my attack isn't showing up in the right place?

I was finishing up my local script, and I'd thought all of the bugs were squashed, accept that the Water - or wavelike block - wasn't showing up by my hand moving forward, rather in the workspace, in a spot right by the spawn. I've been at this for about thirty minutes, but on the last attempt, I got -

Players.fighterkirbyzx.Backpack.WaterShot.LocalScript:13: attempt to index a nil value

Here's the code-


local Water = game.ReplicatedStorage.Water
local Shooter = script.Parent
local Waterclone = Water:Clone()
local Canshoot = true
local person = game.Players.LocalPlayer
local mouse = person:GetMouse()

local function onclick()
		
	Canshoot = false
	
	Waterclone.Parent = game.Workspace
	Waterclone.CFrame = CFrame.new(person:FindFirstChildWhichIsA("RightHand").Position)
	Waterclone.Velocity = Vector3.new(0, 0, 0)	
	
	wait(.8)
	Waterclone:Destroy()

	Canshoot = true
end
	
	mouse.Button1Down:Connect(onclick)

Anyone know why?

5 comments

0

FindFirstChildWhichIsA returns the first object that is of or inherits a given class, or nil if no object of said class exists. RightHand is not a class, but BasePart for example is. Change it to FindFirstChild

0

ill try, thanks!

0

You are right, but the output is the same. Atleast i know tho

0

It doesn’t do damage because its local script. Add RemoteEvent

0

Elaborate. I know what a Remote event is, but how would i use it there?

1 answer

✓ Accepted answer

Easy

In your script person is player not character. Just change it to person.Character

and use FindFirstChild()

local Water = game.ReplicatedStorage.Water
local Shooter = script.Parent
local Waterclone = Water:Clone()
local Canshoot = true
local person = game.Players.LocalPlayer
local mouse = person:GetMouse()

local function onclick()

    Canshoot = false

    Waterclone.Parent = game.Workspace
    Waterclone.CFrame = CFrame.new(person.Character:FindFirstChild("RightHand").Position)
    Waterclone.Velocity = Vector3.new(0, 0, 0)  

    wait(.8)
    Waterclone:Destroy()

    Canshoot = true
end

    mouse.Button1Down:Connect(onclick)

This is why you need to check your script.

10 comments

0

Oh, so the player is like the actual person, while the charactor does the things like click?

0

Character is player's body in workspace. Character can be add / destroy. Player will be remove if the player left the game. Player has a mouse and mouse can click.

0

I forgot to put check if character ~= nil so put it in the first line in function.

0

So, now it says that CFrame is not a valid member of model, what does that mean?

0

Your water is a model?

0

Yeah, does that mean I can't use CFame on it?

0

If yes then use Waterclone:MoveTo(person.Character:FindFirstChild("RightHand").Position)

0

Oh, so use MoveTo instead of CFrame for models?

0

MoveTo is for teleport model but this change position not CFrame. CFrame will change position and rotation.

0

Im so sorry for asking so many questions, but now the actual water - which does do damage - isn't doing damage to anyone when it's made by the script

This discussion is preserved as it was. New answers, comments, and votes are closed.