Alright Moved it there, but now I get this. Even though I have “Main” in PlayerGui
16:09:39.847 Main is not a valid member of PlayerGui "Players.Steamurs.PlayerGui" - Server - Script:1
Alright Moved it there, but now I get this. Even though I have “Main” in PlayerGui
16:09:39.847 Main is not a valid member of PlayerGui "Players.Steamurs.PlayerGui" - Server - Script:1
It hasn’t loaded yet.
Add a delay before all of the scripts work:
task.wait(3)
local PunchScript = game.Players[script.Parent.Parent.Parent.Name].PlayerGui.Main.PunchScript or game.Players:GetPlayerFromCharacter(script.Parent.Parent).PlayerGui.Main.PunchScript
script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
if script.Parent.Parent:IsA("Model") then
PunchScript.Enabled = false
elseif script.Parent.Parent:IsA("BackPack") then
PunchScript.Enabled = true
end
end)
Nevermind. Server scripts can’t access the PlayerGui. Hang on.
Move the PunchScript back into the Tool.
task.wait(3)
local PunchScript = script.Parent.PunchScript
script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
if script.Parent.Parent:IsA("Model") then
PunchScript.Enabled = false
elseif script.Parent.Parent:IsA("BackPack") then
PunchScript.Enabled = true
end
end)
Easy as that…?
I understand that, but why make a custom function over a built-in method? If they serve the same purpose, why not just use the engine’s own method to perform the same function for ease? For one script, sure, but when you start expanding that into other tools, it becomes a chore and a hassle. It seems logical to use GetPropertyChangedSignal for anything other than a tool, but with a tool I don’t see the point of writing a custom function over using a built-in method with equal or faster performance/ better memory safety.
I don’t like using Equipped and Unequipped functions separately. I would rather use one that then checks either of those two.
Should I add something that should loop the script to it? The script only works once and brings back the issue of the tool not working.
I understand that, to each their own I suppose.
How does it only work once? Can you elaborate?
I have had past issues with :GetPropertyChangedSignal()
being buggy. Maybe you should use my inconvenient way, in my opinion: Equipped and Unequipped.
task.wait(3)
local PunchScript = script.Parent.PunchScript
function setScript()
if script.Parent.Parent:IsA("Model") then
PunchScript.Enabled = false
elseif script.Parent.Parent:IsA("BackPack") then
PunchScript.Enabled = true
end
end
script.Parent.Equipped:Connect(function()
setScript()
end)
script.Parent.Unequipped:Connect(function()
setScript()
end)
If I punch before pulling out the tool, I am able to punch. If I use the tool then put it away again I am not able to punch anymore.
This runs me into the same issue. Im still only able to punch before I use the tool
If it works when unequipped but doesn’t when equipped, then switch the properties.
task.wait(3)
local PunchScript = script.Parent.PunchScript
function setScript()
if script.Parent.Parent:IsA("Model") then
PunchScript.Enabled = true --Used to be false.
elseif script.Parent.Parent:IsA("BackPack") then
PunchScript.Enabled = false --Used to be true.
end
end
script.Parent.Equipped:Connect(function()
setScript()
end)
script.Parent.Unequipped:Connect(function()
setScript()
end)
Just edit the whole punch script to add a condition when the tool is held??
Alright this works. Thank you man
No worries! I have all day to help people like you.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.