Hiya! Thank you for clicking on my thread and thanks for reading it in advance.
So basically my issue is, I have a script which creates a rope constraint, that all works however I am having an issue changing a value. In the script you can see I do script.Parent.Shots.Value = script.Parent.Shots.Value - 1
This is done once a remote event is fired to the server. I’ll send a picture of where they’re located etc so you can see. No errors come up in the output
-- Server Script
local shots = script.Parent.Shots.Value
script.Parent.ClickInfo.OnServerEvent:Connect(function(plr, target)
if target.Parent:FindFirstChild("Humanoid") and shots > 0 then
script.Parent.Shots.Value = script.Parent.Shots.Value - 1
script.Parent.Sound:Play()
local hit = script.Parent.HitName.Value
local loc = script.Parent.HitLoc.Value
hit = target.Parent.Name
loc = target.Name
local attatchmentplr = Instance.new("Attachment")
attatchmentplr.Name = "AttatchmentTaser"
attatchmentplr.Position = Vector3.new(0,0,-0.5)
attatchmentplr.Parent = script.Parent
local attatchmentblock = Instance.new("Attachment")
attatchmentblock.Name = "AttatchmentVictim"
attatchmentblock.Position = Vector3.new(0,0.5,0)
attatchmentblock.Parent = target
local ropey = Instance.new("RopeConstraint")
ropey.Attachment0 = attatchmentplr
ropey.Attachment1 = attatchmentblock
ropey.Parent = script.Parent.Union
ropey.Length = 10
ropey.Visible = true
ropey.Color = BrickColor.new("Black")
ropey.Thickness = 0.03
end
end)
This is a common mistake among relatively new scripters, you’re indexing the property of Shots rather than referencing Shots itself:
local shots = script.Parent.Shots --Reference
vs
local shots = script.Parent.Shots.Value --Index
In the case of indexing a property, it will NOT update with the Value property. So even if you update Shots.Value, shots will remain the same. However, in the case of referencing the actual object and checking for shots.Value, it will update the code because you are indexing the property when you need it, instead of at the top of the script.
local shots = script.Parent.Shots
script.Parent.ClickInfo.OnServerEvent:Connect(function(plr, target)
if target.Parent:FindFirstChild("Humanoid") and shots.Value > 0 then
shots.Value = shots.Value - 1
script.Parent.Sound:Play()
local hit = script.Parent.HitName.Value
local loc = script.Parent.HitLoc.Value
hit = target.Parent.Name
loc = target.Name
local attatchmentplr = Instance.new("Attachment")
attatchmentplr.Name = "AttatchmentTaser"
attatchmentplr.Position = Vector3.new(0,0,-0.5)
attatchmentplr.Parent = script.Parent
local attatchmentblock = Instance.new("Attachment")
attatchmentblock.Name = "AttatchmentVictim"
attatchmentblock.Position = Vector3.new(0,0.5,0)
attatchmentblock.Parent = target
local ropey = Instance.new("RopeConstraint")
ropey.Attachment0 = attatchmentplr
ropey.Attachment1 = attatchmentblock
ropey.Parent = script.Parent.Union
ropey.Length = 10
ropey.Visible = true
ropey.Color = BrickColor.new("Black")
ropey.Thickness = 0.03
end
end)