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

Second half of script getting the wrong part?

Asked by 2 years ago

I have a script that checks for a player touching another player, and at the end of the script, it checks for a changed value. The first half works just fine, but the second half where it starts checking for a changed value isn't working.

local grabblock = script.Parent.Torso
local vampchar = script.Parent
grabblock.Touched:Connect(function(grabbedchar)
   if grabbedchar.Parent:FindFirstChild("Humanoid") then
    if vampchar.BeastMode.Value == true and grabbedchar.Parent.Role.Value ~= "Vampire" then
        vampchar.Grabbing.Value = true
        vampchar.GrabbingWho.Value = grabbedchar.Parent.Name
        grabbedchar.Parent.Grabbed.Value = true
        grabbedchar.Parent.GrabbedBy.Value = vampchar.Name
        local moveto = game.ServerStorage.GrabWeld:Clone()
        moveto.Parent = grabbedchar.Parent
            moveto.Attachment0 = grabbedchar.Parent.Torso.GrabAttatch
            moveto.Attachment1 = vampchar.Torso.GrabAttatch
        end
    end
    vampchar.BeastMode.Changed:Connect(function()
        if vampchar.BeastMode.Value == false then
            vampchar.Grabbing.Value = false
            vampchar.GrabbingWho.Value = ""
            grabbedchar.Parent.Grabbed.Value = false
            grabbedchar.Parent.GrabbedBy.Value = ""
        end
    end)
end)

grabbedchar.Parent is supposed to be the character that touched the other character, but on the second half, it starts looking at the character's accesories.

a picture of the errors

1
How about using the explorer to see if the Grabbed value does exist and if does then it’s a script problem and you should prob wait for the item and if it does not exist it prob failed to generate Puppynniko 1059 — 2y
0
The grabbed value does exist, in the character, the script here is erroring because its trying to look inside the accessories of the player for it, the top half of the script does not. Uniplier 83 — 2y

1 answer

Log in to vote
1
Answered by
CDXKIE 130
2 years ago

The problem is at line 16, you’re doing grabbedchar.Parent.BeastMode without checking if whatever touched it is part of the character. Let me explain. - Handle of an accessory touched a part - It gets to the lower part of the script - Handle.Parent is an accessory - You’re not keeping all those values in an accessory.

A fix would be to check if those values exist.

local grabbed = grabbedchar.Parent:FindFirstChild(“Grabbed”)
local grabbedBy = grabbedchar.Parent:FindFirstChild(“grabbedBy”)
if not grabbed or grabbedBy then return end
grabbed.Value = false
grabbedBy.Value = “”
Ad

Answer this question