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

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

Asked by 4 years ago

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?

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 User#24403 69 — 4y
0
ill try, thanks! fighterkirbyzx 102 — 4y
0
You are right, but the output is the same. Atleast i know tho fighterkirbyzx 102 — 4y
0
It doesn’t do damage because its local script. Add RemoteEvent OnaKat 444 — 4y
0
Elaborate. I know what a Remote event is, but how would i use it there? fighterkirbyzx 102 — 4y

1 answer

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
Oh, so the player is like the actual person, while the charactor does the things like click? fighterkirbyzx 102 — 4y
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. OnaKat 444 — 4y
0
I forgot to put check if character ~= nil so put it in the first line in function. OnaKat 444 — 4y
0
So, now it says that CFrame is not a valid member of model, what does that mean? fighterkirbyzx 102 — 4y
View all comments (6 more)
0
Your water is a model? OnaKat 444 — 4y
0
Yeah, does that mean I can't use CFame on it? fighterkirbyzx 102 — 4y
0
If yes then use Waterclone:MoveTo(person.Character:FindFirstChild("RightHand").Position) OnaKat 444 — 4y
0
Oh, so use MoveTo instead of CFrame for models? fighterkirbyzx 102 — 4y
0
MoveTo is for teleport model but this change position not CFrame. CFrame will change position and rotation. OnaKat 444 — 4y
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 fighterkirbyzx 102 — 4y
Ad

Answer this question