ok so what I have going on is that when the player touches the CutPart in the Workspace it changes the BoolVal in the PlayerStarterScript to true, the bandage script checks to see it the BoolVal is true and then allows the player to bandage after being cut.
but what’s happing is the BoolVal is changing to True but not allowing to bandage, but I’ve noticed that if I change the BoolVal to true before hitting the play button it allows me to bandage, so it seems like both scripts are working the way I need them to, but just not work together, the CutScript is changing the BoolVal to true, but it seems like the bandage script isn’t recognizing that it’s been set to true and therefore not bandaging.
Cut Script (Local Script):
local plr = game.Players.LocalPlayer -- References the Players service
local part = game.Workspace.CutPart -- Assuming the script is directly in the part, script.Parent will refer to the part that players will step on
local cutGUI = game.Players.LocalPlayer.PlayerGui.CutGUI.Frame
local cuts = plr.Character.CutVal.Value
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid then
if otherPart.Name == "RightFoot" or "LeftFoot" or "RightHand" or "LeftHand" or "RightLowerArm" or "LeftLowerArm" then
plr.Character.BloodVal.Value -= 360
plr.Character.Cut.Value = true
print(otherPart.Name)
--humanoid:TakeDamage(15)
elseif otherPart.Name == "RightUpperLeg" or "LeftUpperLeg" or "RightUpperArm" or "LeftUpperArm" then
--plr.Character.BloodVal.Value -= 216
print(otherPart.Name)
--humanoid:TakeDamage(50)
elseif otherPart.Name == "UpperTorso" or "LowerTorso" then
--plr.Character.BloodVal.Value -= 360
print(otherPart.Name)
--humanoid:TakeDamage(85)
elseif otherPart.Name == "Head" then
--plr.Character.BloodVal.Value -= 360
print(otherPart.Name)
--humanoid:TakeDamage(85)
end
if cuts then
cuts += 1
print("I'M CUT!!!!!")
end
cutGUI.CutAmount.Text = tostring(cuts)
if plr.Character.BloodVal.Value <= 1000 then
plr.Character.Humanoid.Health -= 50
end
end
end
part.Touched:Connect(player_check)
Bandage Script (Server Script):
local tool = script.Parent
local toolOwner = tool.Parent:IsA("Model") and tool.Parent or tool.Parent:IsA("Backpack") and tool.Parent.Parent.Character
local plr = game.Players:GetPlayerFromCharacter(toolOwner)
local mainchar = plr.Character or plr.CharacterAdded:Wait()
local mainHum = mainchar:WaitForChild("Humanoid")
local healAnim = tool:WaitForChild("HealAnim")
local deb = false
tool.Activated:Connect(function()
if not deb then deb = true
if plr.Character.Cut.Value == true and deb == true then
local healTrack = mainHum:LoadAnimation(healAnim)
print("healing")
healTrack:Play()
healTrack.Stopped:Wait()
--mainHum:UnequipTools(tool)
end
wait()
deb = false --Cooldown
plr.Character.Cut.Value = false
end
end)
ok thank you for your responds, that’s what I figured when it wasn’t working together. Is there a way to do that with what I have now, or is there something you could suggest?
You can send the value from the LocalScript to the Server Script with a RemoteEvent.
Example:
LOCAL SCRIPT:
local remote = script.Parent:WaitForChild("RemoteEvent")
if otherPart.Name == "RightFoot" or "LeftFoot" or "RightHand" or "LeftHand" or "RightLowerArm" or "LeftLowerArm" then
local value = plr.Character.BloodVal.Value -= 360
remote:FireServer(value, plr.Character)
-- rest of your script
end
SERVER SCRIPT:
local remote = script.Parent:WaitForChild("RemoteEvent")
remote.OnServerEvent:Connect(function(player, value, character)
print("Chaning Value")
character.BloodVal.Value = value
end)
There are other events for communicating:
• RemoteEvent (for Server-to-Client or Client-to-Server)
• UnreliableRemoteEvent (same way, but “unreliable” on purpose
• BindableEvent (Client or Server)
ok I see what you’re saying I’m just new to scripting so I’m still a little confused on how I would change the script that I have to the script you are explaining, sorry. Can you add in what you wrote to the script I have so I can see and understand a little better.
Maybe this is enough to set you on the right path:
LOCALSCRIPT:
local remote = script.Parent:WaitForChild("RemoteEvent")
local function player_check(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
remote:FireServer(otherPart)
end
end
part.Touched:Connect(player_check)
SERVER SCRIPT:
local Players = game:GetService("Players")
local remote = script.Parent:WaitForChild("RemoteEvent")
local canTouch = true
remote.OnServerEvent:Connect(function(player, part)
canTouch = false
if Players:FindFirstChild(player.Name) then -- check if player exists
local Player = Players:FindFirstChild(player.Name)
local Character = Player.Character
if Character and Character:FindFirstChild("BloodVal") then -- confirm it exists to prevent script errors
if Character:FindFirstChild("Humanoid") then -- confirm it exists to prevent script errors
if part.Name == "RightFoot" or "LeftFoot" or "RightHand" or "LeftHand" or "RightLowerArm" or "LeftLowerArm" then
player.Character.BloodVal.Value -= 360
player.Character.Cut.Value = true
player.Character.Humanoid:TakeDamage(15)
elseif part.Name == "RightUpperLeg" or "LeftUpperLeg" or "RightUpperArm" or "LeftUpperArm" then
-- script here
elseif part.Name == "UpperTorso" or "LowerTorso" then
-- script here
elseif part.Name == "Head" then
-- script here
end
end
end
end
task.wait(2) -- so the player is not quickly damaged over and over
canTouch = true
end)
ok so i change the scripts over to what you sent me and added Remote Events to each script to be called be “remote” but I’m still getting an Infinite yield possible on 'Workspace.PhaNtoMGamingStudios:WaitForChild(“RemoteEvent”) in the Output not really sure why, if there is a RE as a child.
An easier way would be to just put the entire script on ServerScriptService.
Assuming you have all your CutParts in a folder in Workspace. Like so:
Then you would no longer need a LocalScript. Like so:
– SERVER SCRIPT:
local Players = game:GetService("Players")
local WS = game:GetService("Workspace")
local CutParts = WS:WaitForChild("CutParts")
local canTouch = true
-- run a for loop to apply the script to all parts in the folder
for _, part in pairs(CutParts:GetChildren()) do
-- listen for touched events
local function player_check(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
canTouch = false
if Players:FindFirstChild(otherPart.Parent.Name) then -- check if player exists
local Player = Players:FindFirstChild(otherPart.Parent.Name)
local Character = Player.Character
if Character and Character:FindFirstChild("BloodVal") then -- confirm it exists to prevent script errors
if Character:FindFirstChild("Humanoid") then -- confirm it exists to prevent script errors
if part.Name == "RightFoot" or "LeftFoot" or "RightHand" or "LeftHand" or "RightLowerArm" or "LeftLowerArm" then
Player.Character.BloodVal.Value -= 360
Player.Character.Cut.Value = true
Player.Character.Humanoid:TakeDamage(15)
elseif part.Name == "RightUpperLeg" or "LeftUpperLeg" or "RightUpperArm" or "LeftUpperArm" then
-- script here
elseif part.Name == "UpperTorso" or "LowerTorso" then
-- script here
elseif part.Name == "Head" then
-- script here
end
end
end
end
task.wait(2) -- so the player is not quickly damaged over and over
canTouch = true
end
end
part.Touched:Connect(player_check)
end
well, it’s kind of just something that hurts the player for right now, so I can work on the GUI that show cuts and the bandaging animation I have eventually am going to delete and cause the cuts to happen when a zombie hits the player.
You should still be able to just use a ServerScript with a Touched event.
That way you don’t need to worry about a RemoteEvent from a LocalScript to a Server Script.
Put something like this inside your zombie:
local part = script.Parent:WaitForChild("HumanoidRootPart")
local function player_check(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") and otherPart.Parent.Name ~= "Zombie" then -- so you don't kill anything named "Zombie"
canTouch = false
if Players:FindFirstChild(otherPart.Parent.Name) then -- check if player exists
local Player = Players:FindFirstChild(otherPart.Parent.Name)
local Character = Player.Character
if Character and Character:FindFirstChild("BloodVal") then -- confirm it exists to prevent script errors
if Character:FindFirstChild("Humanoid") then -- confirm it exists to prevent script errors
if part.Name == "RightFoot" or "LeftFoot" or "RightHand" or "LeftHand" or "RightLowerArm" or "LeftLowerArm" then
Player.Character.BloodVal.Value -= 360
Player.Character.Cut.Value = true
Player.Character.Humanoid:TakeDamage(15)
elseif part.Name == "RightUpperLeg" or "LeftUpperLeg" or "RightUpperArm" or "LeftUpperArm" then
-- script here
elseif part.Name == "UpperTorso" or "LowerTorso" then
-- script here
elseif part.Name == "Head" then
-- script here
end
end
end
end
task.wait(2) -- so the player is not quickly damaged over and over
canTouch = true
end
end
part.Touched:Connect(player_check)