Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt event fire when player touched a block? (most likely prob with conditionals)

print("script starts")
local Player
local Part = script.Parent
 local function playerHasTool(player, toolName)
        local tool = player.Backpack:FindFirstChild(toolName) or player.Character:FindFirstChild(toolName)
     if tool then
            return true
        else
            return false
        end
    end
print("Aftertoolrecog")
local Player
 Part.Touched:Connect(function(HIT)
        Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
        local H  = HIT.Parent:FindFirstChild("Humanoid")
     print("Before conditional")
if H and not playerHasTool(Player,"MediterraneanAvenue") and not game.ReplicatedStorage:FindFirstChild("MediterraneanAvenue") then

print("Conditional checked")
game.ReplicatedStorage.PayRent:FireClient(Player)
print("event fired")
end
 end)

this script is supposed to fire the event when a player steps on a part in workspace (this is a script inside that part in workspace). The conditionals work well in test mode but when I try it after publishing the game, it doent work. Why does this happen? Please help me!

1 comment

0

Try enabling studio api services..

1 answer

I assume that your condition only fires when the player doesn't have the tool which name is MediterraneanAvenue.

In this case as I assumed, you don't need this statement to be false:

game.ReplicatedStorage:FindFirstChild("MediterraneanAvenue")

, so I adjusted your code a little bit.


print("script starts")
local Player
local Part = script.Parent
 local function playerHasTool(player, toolName)
        local tool = player.Backpack:FindFirstChild(toolName) or player.Character:FindFirstChild(toolName)
     if tool then
            return true
        else
            return false
        end
    end
print("Aftertoolrecog")
local Player
 Part.Touched:Connect(function(HIT)
        Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
        local H  = HIT.Parent:FindFirstChild("Humanoid")
     print("Before conditional")
if H and not playerHasTool(Player,"MediterraneanAvenue") then

print("Conditional checked")
game.ReplicatedStorage.PayRent:FireClient(Player)
print("event fired")
end
 end)

Warning: This is the final code as what I assumed, regarding to that you didn't provide any further details of your codes.

2 comments

0

no i need the other statement also

0

Add it yourself, you know how to do it...

This discussion is preserved as it was. New answers, comments, and votes are closed.