So this is my server script that tells the remote event what to do(it works)
game.ReplicatedStorage.HatDestroy.OnServerEvent:Connect(function(player)
local char = player.Character
if char then
for i,v in pairs(char:GetChildren()) do
if v.Name == "Humanoid" then
v:RemoveAccessories()
end
end
for i,v in pairs(char:GetChildren()) do
if v.Name == "Head" then
v.face.Transparency = 1
else
return
end
end
end
end)
This is my original script in StarterPlayer > StaterCharacterScripts that I made for testing, and when I use “game.Workspace.Lava” it works
db = false
game.Workspace.Lava.Touched:Connect(function()
if db == false then
db = true
game.ReplicatedStorage.HatDestroy:FireServer()
end
wait(5)
db = false
end)
I’m now trying to move the LocalScript from StarterCharacterScripts into a part using the script.Parent.Touched event but it isn’t working.
db = false
script.Parent.Touched:Connect(function()
if db == false then
db = true
game.ReplicatedStorage.HatDestroy:FireServer()
end
wait(5)
db = false
end)
I’ve just recently gotten back into coding and I’m not very good yet, so I’m sure there is something I’m doing wrong here, but I would appreciate being pointed in the right direction if anyone knows whats going on.
Just tried, and yeah it’s not printing for the new Touched statement that uses script.Parent, seems my debounce isnt working on the original one either because it’s spamming prints
First of all just gonna fix some code here for you are there are a few things wrong with the original.
db = false
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if db == false then
db = true
game.ReplicatedStorage.HatDestroy:FireServer()
wait(5)
db = false
end
end
end)
The script that is detecting the touch is a LocalScript. If you’re saying it wont even print anything when touched I would consider looking to see if the script is even running. LocalScripts do not run when parented to workspace.
yes, so for example my game this is going into is a tycoon. I’m adding this script into one of the Morph givers. I cant figure out any other way to determine which part is to be touched (in the original scripts its game.Workspace.Lava) but in the tycoons its like game.Workspace.TycoonKit.Tycoon1.Purchases and there’s 4 different tycoons. I was using script.Parent to determine what part the player actually touches to fire the remote event because originally the localscript is in StarterPlayerScripts and says game.Workspace.Lava.Touched:Connect(function()
Why not use a ServerScript instead of a LocalScript?
script.Parent.Touched:Connect(function(Hit)
if not Hit.Parent:FindFirstChild("Humanoid") then return end;
local char = Hit.Parent
if char then
for i,v in pairs(char:GetChildren()) do
if v.Name == "Humanoid" then
v:RemoveAccessories()
end
end
for i,v in pairs(char:GetChildren()) do
if v.Name == "Head" then
v.face.Transparency = 1
else
return
end
end
end
end)
I thought for Remove Events that you have to fire the event from the client through a local script. Then the server script tells the remove event what to do.
Yes but there is no need for a RemoteEvent. You can remove the Hats and detect the Touched from a server script. See my previous response for an example.
Edit: Ill provide better code for you, give me a moment.
script.Parent.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
Humanoid:RemoveAccessories()
if Humanoid.Parent.Head.face then
Humanoid.Parent.Head.face:Destroy()
end
end
end)
Just to let you know Are31 Remote events Can be fired from client and server for Example from server you say RemoteEvent:FireAllClients() But for Local Scripts you use RemoteEvent:FireServer() I hope this help you and taught you a little bit