alright so basically, i made a part or “zone” thats supposed to change the colour of the water, when you walk into it. It works, but for some reason whenever a tool is equipped, it will change the colour of the water despite me using FindFirstChild(). Any idea whats wrong with it?
code:
local terrain = game.Workspace.Terrain
local tweenservic = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear)
local red = {WaterColor = Color3.fromRGB(255, 0, 4)}
local blue = {WaterColor = Color3.fromRGB(12, 84, 92)}
local changered = tweenservic:Create(terrain, info, red)
local changeblue = tweenservic:Create(terrain, info, blue)
game.Workspace["Chagne water"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
changered:Play()
end
end)
game.Workspace["Chagne water"].TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
changeblue:Play()
end
end)
try this instead, this is how i always check if a player hit and without the paret:FindFirstChild
if it works, i’d love if you solution this
local terrain = game.Workspace.Terrain
local tweenservic = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear)
local red = {WaterColor = Color3.fromRGB(255, 0, 4)}
local blue = {WaterColor = Color3.fromRGB(12, 84, 92)}
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local changered = tweenservic:Create(terrain, info, red)
local changeblue = tweenservic:Create(terrain, info, blue)
game.Workspace["Chagne water"].Touched:Connect(function(hit)
if hit:IsDescendantOf(Character) then
changered:Play()
end
end)
game.Workspace["Chagne water"].TouchEnded:Connect(function(hit)
if it:IsDescendantOf(Character) then
changeblue:Play()
end
end)
Where are you checking for a Humanoid?
I just see IsDescendandOf(Character).
Try:
game.Workspace["Chagne water"].Touched:Connect(function(hit)
if hit:IsDescendantOf(Character) and not hit.Parent.ClassName == "Tool" then
changered:Play()
end
end)
Be aware I’m not exactly sure if that’s the correct terminology or heirarchy. If your tool has multiple Parts it may cause issues. If it’s just one Part named Handle then your could probably use hit.Name == "Handle"
EDIT Sorry, was looking at @capsori’s post.
Doing a double check to see if it’s a tool is probably still a good idea.
Uhh when you equip a tool its placed inside your character, meaning your code finds a humanoid in the parent of the tool and triggers the code
You need to check if hit is a tool or character part
You could do this by naming the tool, “tool” so you know its a tool, or whatever indicates that hit Is a tool
It would look something like this:
if hit.Name ~= “Tool” and hit.Parent:FindFirstChild("Humanoid") then
local terrain = script.Parent
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(1)
local red = {WaterColor = Color3.fromRGB(255, 0, 4)}
local blue = {WaterColor = Color3.fromRGB(12, 84, 92)}
local changered = tweenService:Create(terrain, info, red)
local changeblue = tweenService:Create(terrain, info, blue)
local function handleTouched(hit)
local character = hit.Parent:FindFirstChild("Humanoid")
if character and not hit.Parent:FindFirstChild("Tool") then
changered:Play()
end
end
local function handleTouchEnded(hit)
local character = hit.Parent:FindFirstChild("Humanoid")
if character and not hit.Parent:FindFirstChild("Tool") then
changeblue:Play()
end
end
script.Parent["Chagne water"].Touched:Connect(handleTouched)
script.Parent["Chagne water"].TouchEnded:Connect(handleTouchEnded)
Are people forgetting that the Touched event will fire multiple times depending on the amount of parts that touch it? Simply check on both occasions if the part is the HumanoidRootPart, then it should only account for one hit. If this is a server script you want everyone to influence, simply use a method that checks for all touching parts.
the issue is not that the event is firing multiple times or whatever, the issue is that whenever you equip a tool, for some reason it registers as the player leaving the zone. which i am trying to figure out how to fix.
also yes i did try checking if hit.parent:FindFirstChild(“HumanoidRootPart”), it works the same as using the humanoid only, but it does not solve the issue of “equipping a tool will for some reason count as leaving the zone”. And i also tried making an arguement where if hit.parent :findfirstchild(“tool”), then it shouldnt fire, but still.
edit heres the script aswell that i used in that video:
local tweenservic = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear)
local red = {WaterColor = Color3.fromRGB(255, 0, 4)}
local blue = {WaterColor = Color3.fromRGB(12, 84, 92)}
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local changered = tweenservic:Create(terrain, info, red)
local changeblue = tweenservic:Create(terrain, info, blue)
game.Workspace["Change water"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent.Name ~= "Radio" then
changered:Play()
end
end)
game.Workspace["Change water"].TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent.Name ~= "Radio" then
changeblue:Play()
elseif hit.Parent:FindFirstChild("Handle") then
print("rizz")
end
end)
local ToolModel = MODELHERE
game.Workspace["Change water"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") and not hit:IsDescendantOf(ToolModel) then
changered:Play()
elseif hit:IsDescrndantOf(ToolModel) then
print(“tool”)
end
end)
Tried it, but unfortunately now it only works if the player is holding the tool, which i mean technically solves the issue of the script thinking the player left the zone, but if the player isnt holding the tool, then an error will appear.