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

Trying to make a door break script but an error shows up and the obj value dosen't change?

Asked by
RootEntry 111
6 years ago
Edited 6 years ago

I am trying to make a script where you can break doors and walls for a game. But when I click on it there displays an error.

Error: "11:30:47.281 - Players.iiLevelMaker.PlayerGui.ScreenGui.Frame.HealthBG.Bar.LocalScript:10: attempt to index field 'Value' (a nil value)"

Serverscript (Inside Part):

script.Parent.ClickDetector.MouseClick:connect(function(player)
    local obj = script.Parent

    game:GetService("ReplicatedStorage").cutWood:FireClient(player, obj)
end)

LocalScript (Inside the "Bar" object seen in the error) 1st:

local player = game.Players.LocalPlayer
local obj = script.Parent.Obj

script.Parent.Health.Changed:connect(function(player)
    local prog = script.Parent.Health

    script.Parent:TweenSize(UDim2.new(prog.Value/100, 0, 1, 0), "In", "Linear", .1)
    if prog.Value <= 0 then
        prog.Value = 0
        obj.Value.Anchored = false
    end
end)

2nd Local script:

game:GetService("ReplicatedStorage").cutWood.OnClientEvent:connect(function(player, obj)
    script.Parent.Obj.Value = obj
    script.Parent.Health.Value = script.Parent.Health.Value - 10
end)

The health works fine, but the "Obj" value wont change, it's a objectvalue. It's supposed to change to the part the player is hitting.

1 answer

Log in to vote
1
Answered by 6 years ago

Your ServerScript and 2nd LocalScript are fine, but there are 2 things wrong in the 1st LocalScript

First of all: 'Anchored' IS a value. If you were trying to change it to false then you just have to put it like this

obj.Anchored = false

However, if you wanted to change a value's 'Anchored' property then it's not possible. It doesn't even make sense. A value isn't something physical, it's just a value.

Second of all: If you put 'player' in your function's brackets you don't need to define 'player' before the function.

Ad

Answer this question